This is the main class providing the configuration behind the MVC Java config. It is typically imported by adding {@link EnableWebMvc @EnableWebMvc} to an application {@link Configuration @Configuration} class. An alternative more advanced option is to extend directly from this class and override methods as necessary remembering to add {@link Configuration @Configuration} to the subclass and {@link Bean @Bean} to overridden {@link Bean @Bean} methods.For more details see the Javadoc of {@link EnableWebMvc @EnableWebMvc}.
This class registers the following {@link HandlerMapping}s:
- {@link RequestMappingHandlerMapping} ordered at 0 for mapping requests to annotated controller methods.
- {@link HandlerMapping} ordered at 1 to map URL paths directly to view names.
- {@link BeanNameUrlHandlerMapping} ordered at 2 to map URL paths to controller bean names.
- {@link HandlerMapping} ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests.
- {@link HandlerMapping} ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet.
Registers these {@link HandlerAdapter}s:
- {@link RequestMappingHandlerAdapter} for processing requests with annotated controller methods.
- {@link HttpRequestHandlerAdapter} for processing requests with {@link HttpRequestHandler}s.
- {@link SimpleControllerHandlerAdapter} for processing requests with interface-based {@link Controller}s.
Registers a {@link HandlerExceptionResolverComposite} with this chain ofexception resolvers:
- {@link ExceptionHandlerExceptionResolver} for handling exceptions through @ {@link ExceptionHandler} methods.
- {@link ResponseStatusExceptionResolver} for exceptions annotated with @ {@link ResponseStatus}.
- {@link DefaultHandlerExceptionResolver} for resolving known Spring exception types
Both the {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver} are configured with default instances of the following kind, unless custom instances are provided:
- A {@link DefaultFormattingConversionService}
- A {@link LocalValidatorFactoryBean} if a JSR-303 implementation is available on the classpath
- A range of {@link HttpMessageConverter}s depending on the 3rd party libraries available on the classpath.
@see EnableWebMvc
@see WebMvcConfigurer
@see WebMvcConfigurerAdapter
@author Rossen Stoyanchev
@since 3.1