This is the main class providing the configuration behind the MVC Java config. It is typically imported by adding {@link EnableWebMvc @EnableWebMvc} to anapplication {@link Configuration @Configuration} class. An alternative moreadvanced option is to extend directly from this class and override methods as necessary remembering to add {@link Configuration @Configuration} to thesubclass 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 exceptionsthrough @ {@link ExceptionHandler} methods.
- {@link ResponseStatusExceptionResolver} for exceptions annotatedwith @ {@link ResponseStatus}.
- {@link DefaultHandlerExceptionResolver} for resolving known Springexception types
Registers an {@link AntPathMatcher} and a {@link UrlPathHelper}to be used by:
- the {@link RequestMappingHandlerMapping},
- the {@link HandlerMapping} for ViewControllers
- and the {@link HandlerMapping} for serving resources
Note that those beans can be configured with a {@link PathMatchConfigurer}.
Both the {@link RequestMappingHandlerAdapter} and the{@link ExceptionHandlerExceptionResolver} are configured with defaultinstances of the following by default:
- a {@link ContentNegotiationManager}
- a {@link DefaultFormattingConversionService}
- a {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean}if a JSR-303 implementation is available on the classpath
- a range of {@link HttpMessageConverter}s depending on the third-party libraries available on the classpath.
@author Rossen Stoyanchev
@author Brian Clozel
@author Sebastien Deleuze
@since 3.1
@see EnableWebMvc
@see WebMvcConfigurer
@see WebMvcConfigurerAdapter