In Spring Boot, _____ annotation is used to map HTTP POST requests onto specific handler methods.

  • @Controller
  • @GetMapping
  • @PostMapping
  • @RequestMapping
In Spring Boot, the @PostMapping annotation is used to map HTTP POST requests onto specific handler methods in a controller class. When you apply this annotation to a method, it tells Spring that this method should be invoked when an HTTP POST request with a matching URL is received. It's a key annotation for handling POST requests in a RESTful API.

Imagine you are developing a Spring Boot application where you need to implement a complex request mapping strategy with custom conditions. How would you achieve this?

  • Configuring complex conditions in the application properties.
  • Creating a separate utility class for custom mappings.
  • Implementing a custom RequestMappingHandlerMapping.
  • Using annotations like @RequestMapping for complex mapping.
To implement a complex request mapping strategy with custom conditions, you would typically need to create a custom RequestMappingHandlerMapping. This allows you to define intricate conditions and behaviors for mapping requests to controller methods. Using annotations or configuration properties alone may not provide the level of customization needed for complex mappings. A separate utility class may not integrate seamlessly with Spring Boot's request handling mechanism.

Which annotation is primarily used in Spring Boot to mark the main class of your application?

  • @MainClass
  • @SpringBootApplication
  • @SpringBootClass
  • @SpringMain
In Spring Boot, the primary annotation used to mark the main class of your application is @SpringBootApplication. This annotation not only marks the class as the main entry point but also enables various Spring Boot features like auto-configuration, component scanning, and more. It's the starting point for your Spring Boot application.

How can application properties be overridden in Spring Boot for different environments?

  • By annotating the @OverrideProperties annotation on the class.
  • By creating multiple instances of the SpringApplication class.
  • By modifying the application.properties directly.
  • Using environment-specific property files.
Application properties in Spring Boot can be overridden for different environments by using environment-specific property files. By naming these files application-{profile}.properties (e.g., application-dev.properties for the 'dev' profile), Spring Boot can load the properties specific to the active profile, allowing you to configure different settings for each environment. This is a key feature for maintaining configurations across various deployment scenarios.

To create conditional beans within custom Auto Configuration, you can use the @_____ annotation with a specific condition.

  • ConditionalOnBean
  • ConditionalOnClass
  • ConditionalOnMethod
  • ConditionalOnProperty
To create conditional beans within custom Auto Configuration, you can use the @ConditionalOnClass annotation. This annotation allows you to specify that a particular bean should be created only if a specified class is present in the classpath. It's useful for scenarios where you want to conditionally configure beans based on the availability of certain classes.

To perform unit testing on the web layer of a Spring Boot application without loading the complete context, use the _____ annotation.

  • @SpringBootTest
  • @UnitTest
  • @WebLayerTest
  • @WebMvcTest
To perform unit testing on the web layer of a Spring Boot application without loading the complete context, you should use the @WebMvcTest annotation. This annotation focuses only on the web layer and is suitable for testing controllers.

In a Spring Boot application, the _____ annotation is used to demarcate transaction boundaries.

  • @Autowired
  • @Component
  • @Service
  • @Transactional
In a Spring Boot application, the @Transactional annotation is used to demarcate transaction boundaries. It is applied to methods, indicating that the method should be wrapped in a transaction, ensuring that either all operations within the method succeed or none of them do. This is crucial for maintaining data consistency in the database.

How does the @PreAuthorize annotation in Spring Security differ from the @Secured annotation in terms of the conditions that can be applied?

  • @PreAuthorize allows for complex SpEL (Spring Expression Language) expressions for fine-grained control
  • @PreAuthorize is deprecated, and @Secured should be used
  • @PreAuthorize only works with roles while @Secured allows for custom conditions
  • @Secured is more powerful than @PreAuthorize
The @PreAuthorize annotation in Spring Security allows for complex SpEL expressions to define fine-grained access control conditions. This means you can use expressions involving multiple variables and logic, making it more versatile than @Secured, which primarily works with roles.

What is the primary purpose of the @SpringBootApplication annotation in a Spring Boot application?

  • To allow configuration classes.
  • To define a main method.
  • To enable Spring MVC support.
  • To enable component scanning.
The @SpringBootApplication annotation in Spring Boot is a convenience annotation that adds all of the following: @Configuration, @EnableAutoConfiguration, and @ComponentScan. Thus, it enables component scanning, allowing Spring to automatically discover and register beans. This is crucial for allowing the Spring context to be aware of all the components, services, repositories, etc. available in the project.

For implementing client credentials grant in a Spring Boot application, the client must send a request to the token endpoint with _____ grant type.

  • authorization_code
  • implicit
  • client_credentials
  • password
To implement the client credentials grant in a Spring Boot application, the client must send a request to the token endpoint with the client_credentials grant type. This grant type is used when the client, typically a service or application, needs to authenticate itself directly with the authorization server to obtain an access token. The other options are different OAuth2 grant types used for various scenarios.