How can you exclude a specific auto-configuration class in a Spring Boot application?

  • Exclude it using the @ConfigurationProperties annotation.
  • Specify exclusions in the application.properties file.
  • Use the @ExcludeAutoConfig annotation.
  • Use the @NoAutoConfiguration annotation.
To exclude a specific auto-configuration class in a Spring Boot application, you can specify exclusions in the application.properties file using the spring.autoconfigure.exclude property. This property allows you to list the fully-qualified names of the auto-configuration classes you want to exclude, ensuring they are not applied to your application.

You are tasked with implementing a Single Sign-On (SSO) solution using OAuth2 and JWT in a microservices architecture. How would you approach designing and implementing the SSO solution?

  • Implement OAuth2 and JWT separately in each microservice to ensure independence.
  • Implement a centralized OAuth2 and JWT service that manages SSO for all microservices.
  • Use a combination of OAuth2 and OpenID Connect (OIDC) for SSO, with each microservice managing its own JWTs.
  • Implement SAML-based SSO for simplicity and ease of integration in a microservices architecture.
In a microservices architecture, a centralized approach (option 2) for implementing SSO with OAuth2 and JWT is recommended. This centralization ensures uniformity and ease of management across all microservices. Implementing OAuth2 and JWT separately (option 1) could lead to inconsistency and complexity. While OAuth2 and OIDC (option 3) can be used together, they might not provide the same simplicity as a centralized solution. SAML-based SSO (option 4) is an alternative but may not be the best fit for a microservices setup.

In cases where a required dependency is not found, the @Autowired annotation will throw a _____.

  • NoSuchBeanDefinitionException
  • BeanCreationException
  • DependencyNotFoundException
  • AutowireException
In cases where a required dependency is not found, the @Autowired annotation will throw a BeanCreationException. This exception occurs when Spring cannot find a suitable bean to inject for a required dependency. The other options, such as NoSuchBeanDefinitionException, DependencyNotFoundException, and AutowireException, are not the standard exceptions thrown by @Autowired in this scenario.

How can you customize the response status code of a controller method in Spring Boot?

  • By returning an instance of ResponseEntity with a custom status code.
  • By using the @ResponseStatus annotation with the desired code.
  • Modifying the application.properties file with a custom code.
  • Configuring the status code in the @GetMapping annotation.
To customize the response status code of a controller method in Spring Boot, you can return an instance of ResponseEntity with a custom status code. This allows fine-grained control over the response, including status codes, headers, and response bodies. The @ResponseStatus annotation is used to declare the default status code for the entire controller class, not for individual methods. The other options are not standard ways to customize the status code.

In Spring Boot, to create a RESTful web service, you would typically use the _____ annotation on a controller class.

  • @Controller
  • @RequestMapping
  • @RequestMapping and @RestController
  • @RestController
In Spring Boot, to create a RESTful web service, you typically use the @RestController annotation on a controller class. This annotation combines the functionality of both the @Controller and @ResponseBody annotations, making it convenient for creating RESTful endpoints that return data directly in the response body, without the need for a view.

In Spring Security, a custom access decision voter can be created to use with method security by implementing the _____ interface.

  • AccessDecisionVoter
  • Authentication
  • Authorization
  • UserDetails
In Spring Security, a custom access decision voter can be created by implementing the AccessDecisionVoter interface. This interface allows you to define your own logic for making access control decisions when using method security.

The process of creating a JWT token in Spring Boot is known as _____.

  • JWT generation
  • JWT signing
  • Token creation
  • Tokenization
In Spring Boot, the process of creating a JWT (JSON Web Token) is known as "JWT signing." It involves digitally signing the token to ensure its authenticity and integrity. JWTs are commonly used for authentication and authorization in web applications.

When performing integration testing in Spring Boot, which of the following is used to load only specific slices of the application?

  • @AutoConfigureMockMvc
  • @DataJpaTest
  • @SpringBootTest
  • @WebMvcTest
The @WebMvcTest annotation is used to load only specific slices of the application, typically focused on testing web controllers and related components in a Spring Boot application.

In Spring Boot, how can you customize the default error attributes in the default error response?

  • By creating a custom error controller and overriding the default error handling logic.
  • By modifying the error properties in the application's application.properties or application.yml file.
  • By using the @ErrorAttributes annotation on controller methods.
  • By disabling the default error response and implementing a custom error handling mechanism.
To customize the default error attributes in the default error response in Spring Boot, you can modify the error properties in the application's application.properties or application.yml file. This allows you to tailor the error responses according to your application's requirements. The other options either involve creating unnecessary complexity or are not standard practices for customizing error attributes.

What is the primary purpose of the @Cacheable annotation in Spring Boot?

  • To define cache entry eviction policies.
  • To specify cache names for grouping.
  • To indicate that a method's results should be cached.
  • To clear the cache completely.
The primary purpose of the @Cacheable annotation in Spring Boot is to indicate that a method's results should be cached. You annotate a method with @Cacheable, and Spring Boot caches the results of that method, allowing for faster access in subsequent calls. The other options are not the primary purpose of @Cacheable.