1. What is the main change in Spring 5.0 regarding the WebMvcConfigurer interface?
Why: Since Spring 5.0, WebMvcConfigurer has Java 8 default methods, allowing you to implement it directly without extending the adapter class.
2. Why is WebMvcConfigurerAdapter no longer needed in Spring 5.0 and later?
Why:WebMvcConfigurerAdapter is deprecated in Spring 5.0 because WebMvcConfigurer now has default methods, so you can implement the interface directly.
3. Which annotation is used to enable Spring MVC configuration in a Java class?
@Configuration
// Add annotation here
public class MyWebConfig implements WebMvcConfigurer { ... }
Why:@EnableWebMvc is the standard annotation to enable Spring MVC infrastructure in a @Configuration class.
4. What is the purpose of the configureViewResolvers method in WebMvcConfigurer?
Why:configureViewResolvers allows you to register and configure view resolvers, such as JSP or Thymeleaf, used to render views.
5. Which method is used to map a URL directly to a view without a controller?
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// Which method call maps a URL to a view?
}
Why: The addViewController method on ViewControllerRegistry is used to map a URL directly to a view name without a controller.
6. What does the ViewControllerRegistry help to achieve?
Why:ViewControllerRegistry allows you to map specific URLs to view names directly, bypassing the need for a controller.
7. In Spring 5.0+, what is the recommended way to customize MVC configuration?
Why: Since WebMvcConfigurer has default methods in Spring 5.0, implementing it directly is the recommended approach.
8. What Java version is required to use the default methods in WebMvcConfigurer?
Why: Default methods in interfaces are a Java 8 feature, so Java 8 or higher is required.
9. Which method is used to register a view resolver that resolves JSP views?
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
// Which call configures JSP view resolution?
}
Why: The jsp method on ViewResolverRegistry is a convenient way to configure an InternalResourceViewResolver for JSP views.
10. What is the role of @Configuration in a class that implements WebMvcConfigurer?
Why:@Configuration indicates that the class is a configuration class that can contain bean definitions and be processed by the Spring container.
11. Which component is responsible for delegating requests to the appropriate handlers in Spring MVC?
Why: The DispatcherServlet is the front controller that receives all requests and delegates them to the appropriate handlers.
12. What happens if you override a default method in WebMvcConfigurer?
Why: When you override a default method, your implementation replaces the default behavior, allowing you to customize the configuration.
13. Which interface must a configuration class implement to customize Spring MVC using default methods?
@Configuration
@EnableWebMvc
public class MyConfig implements ________ { ... }
Why: The WebMvcConfigurer interface provides default methods for customizing Spring MVC configuration.
14. What is the primary benefit of using default methods in WebMvcConfigurer?
Why: Default methods allow you to override only the methods relevant to your configuration, without providing empty implementations for all other methods.
15. Which registry is passed to the addViewControllers method?
Why: The addViewControllers method receives a ViewControllerRegistry that is used to register view controllers.