1. What is the primary purpose of the @EnableWebMvc annotation in Spring Framework?
Why: The @EnableWebMvc annotation is used to enable the core Spring MVC infrastructure, including key components like RequestMappingHandlerMapping and RequestMappingHandlerAdapter.
2. On which type of class is the @EnableWebMvc annotation typically applied?
Why:@EnableWebMvc is typically placed on a class annotated with @Configuration to define a Java-based configuration for Spring MVC components.
3. Which component, enabled by @EnableWebMvc, is responsible for mapping incoming HTTP requests to specific handler methods?
Why: The RequestMappingHandlerMapping component is responsible for inspecting handler methods and matching them to incoming requests based on annotations like @RequestMapping, @GetMapping, etc.
4. What is the primary role of RequestMappingHandlerAdapter, enabled by @EnableWebMvc?
Why: The RequestMappingHandlerAdapter is responsible for invoking the handler methods found by RequestMappingHandlerMapping, including processing arguments and handling return values.
5. How can one customize the default Spring MVC configuration provided by @EnableWebMvc?
Why: To customize the default configuration enabled by @EnableWebMvc, you should implement the WebMvcConfigurer interface and override its methods.
6. What happens when @EnableWebMvc is used in a Spring Boot application?
Why: In a Spring Boot application, using @EnableWebMvc typically disables the auto-configuration provided by WebMvcAutoConfiguration, allowing the developer to take full control of the MVC setup.
7. Which of the following is NOT directly provided or automatically configured by @EnableWebMvc itself, but rather its infrastructure supports it?
Why: While @EnableWebMvc sets up the infrastructure for view resolution, it does not automatically create and configure a specific InternalResourceViewResolver. That needs to be explicitly configured, often through WebMvcConfigurer.
8. Which infrastructure component is enabled by @EnableWebMvc to facilitate conversion between HTTP request/response bodies and Java objects (e.g., JSON, XML)?
Why:@EnableWebMvc enables the infrastructure for MessageConverters, which are crucial for converting request bodies into objects and objects into response bodies (e.g., for REST APIs).
9. For what purpose does @EnableWebMvc enable ExceptionHandlerExceptionResolver?
Why:@EnableWebMvc enables the ExceptionHandlerExceptionResolver, which allows methods annotated with @ExceptionHandler within controllers or @ControllerAdvice classes to handle exceptions.
10. Which interface allows you to register custom Formatters or Converters when using @EnableWebMvc?
Why: The WebMvcConfigurer interface provides methods like addFormatters to register custom Formatters and Converters to handle data type conversions.
11. What is the main reason @EnableWebMvc is often not explicitly needed in typical Spring Boot applications?
Why: Spring Boot's WebMvcAutoConfiguration automatically configures most common Spring MVC features, making @EnableWebMvc redundant unless you need fine-grained control or want to disable auto-configuration.
12. When configuring Spring MVC with @EnableWebMvc, what is the purpose of registering a Validator?
Why:@EnableWebMvc enables infrastructure for a Validator, typically for validating user input from web forms or request bodies against defined constraints.
13. Which class provides the default configuration that @EnableWebMvc effectively imports?
Why: The @EnableWebMvc annotation effectively imports the default Spring MVC configuration provided by the EnableWebMvcConfiguration class.
14. If you need to configure static resource handling (like CSS, JS, images) when using @EnableWebMvc, which interface method would you typically override?
Why: The addResourceHandlers method of the WebMvcConfigurer interface is used to configure how static resources are served in a Spring MVC application.
15. Does @EnableWebMvc automatically scan for @Controller or @RestController annotated classes?
Why:@EnableWebMvc enables the core MVC infrastructure. The actual discovery of @Controller or @RestController beans typically relies on Spring's component scanning mechanism (e.g., via @ComponentScan), not directly on @EnableWebMvc itself.