Class WebMvcConfigurerAdapter
- java.lang.Object
- org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
- All Implemented Interfaces:
WebMvcConfigurer
public abstract class WebMvcConfigurerAdapter extends Object implements WebMvcConfigurer
An implementation ofWebMvcConfigurerwith empty methods allowing subclasses to override only the methods they're interested in.- Since:
- 3.1
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description WebMvcConfigurerAdapter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)Add resolvers to support custom controller method argument types.voidaddCorsMappings(CorsRegistry registry)Configure cross origin requests processing.voidaddFormatters(FormatterRegistry registry)voidaddInterceptors(InterceptorRegistry registry)Add Spring MVC lifecycle interceptors for pre- and post-processing of controller method invocations.voidaddResourceHandlers(ResourceHandlerRegistry registry)Add handlers to serve static resources such as images, js, and, css files from specific locations under web application root, the classpath, and others.voidaddReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)Add handlers to support custom controller method return value types.voidaddViewControllers(ViewControllerRegistry registry)Configure simple automated controllers pre-configured with the response status code and/or a view to render the response body.voidconfigureAsyncSupport(AsyncSupportConfigurer configurer)Configure asynchronous request handling options.voidconfigureContentNegotiation(ContentNegotiationConfigurer configurer)Configure content negotiation options.voidconfigureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)Configure a handler to delegate unhandled requests by forwarding to the Servlet container's "default" servlet.voidconfigureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)Configure exception resolvers.voidconfigureMessageConverters(List<HttpMessageConverter<?>> converters)Configure theHttpMessageConverters to use for reading or writing to the body of the request or response.voidconfigurePathMatch(PathMatchConfigurer configurer)Helps with configuring HandlerMappings path matching options such as trailing slash match, suffix registration, path matcher and path helper.voidconfigureViewResolvers(ViewResolverRegistry registry)Configure view resolvers to translate String-based view names returned from controllers into concreteViewimplementations to perform rendering with.voidextendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)Extending or modify the list of exception resolvers configured by default.voidextendMessageConverters(List<HttpMessageConverter<?>> converters)A hook for extending or modifying the list of converters after it has been configured.MessageCodesResolvergetMessageCodesResolver()Provide a customMessageCodesResolverfor building message codes from data binding and validation error codes.ValidatorgetValidator()Provide a customValidatorinstead of the one created by default.
Constructor Detail
WebMvcConfigurerAdapter
public WebMvcConfigurerAdapter()
Method Detail
configurePathMatch
public void configurePathMatch(PathMatchConfigurer configurer)
Helps with configuring HandlerMappings path matching options such as trailing slash match, suffix registration, path matcher and path helper. Configured path matcher and path helper instances are shared for:- RequestMappings
- ViewControllerMappings
- ResourcesMappings
This implementation is empty.
- Specified by:
configurePathMatchin interfaceWebMvcConfigurer
configureContentNegotiation
public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
Configure content negotiation options.This implementation is empty.
- Specified by:
configureContentNegotiationin interfaceWebMvcConfigurer
configureAsyncSupport
public void configureAsyncSupport(AsyncSupportConfigurer configurer)
Configure asynchronous request handling options.This implementation is empty.
- Specified by:
configureAsyncSupportin interfaceWebMvcConfigurer
configureDefaultServletHandling
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
Configure a handler to delegate unhandled requests by forwarding to the Servlet container's "default" servlet. A common use case for this is when theDispatcherServletis mapped to "/" thus overriding the Servlet container's default handling of static resources.This implementation is empty.
- Specified by:
configureDefaultServletHandlingin interfaceWebMvcConfigurer
addFormatters
public void addFormatters(FormatterRegistry registry)
AddConverters andFormatters in addition to the ones registered by default.This implementation is empty.
- Specified by:
addFormattersin interfaceWebMvcConfigurer
addInterceptors
public void addInterceptors(InterceptorRegistry registry)
Add Spring MVC lifecycle interceptors for pre- and post-processing of controller method invocations. Interceptors can be registered to apply to all requests or be limited to a subset of URL patterns.Note that interceptors registered here only apply to controllers and not to resource handler requests. To intercept requests for static resources either declare a
MappedInterceptorbean or switch to advanced configuration mode by extendingWebMvcConfigurationSupportand then overrideresourceHandlerMapping.This implementation is empty.
- Specified by:
addInterceptorsin interfaceWebMvcConfigurer
addResourceHandlers
public void addResourceHandlers(ResourceHandlerRegistry registry)
Add handlers to serve static resources such as images, js, and, css files from specific locations under web application root, the classpath, and others.This implementation is empty.
- Specified by:
addResourceHandlersin interfaceWebMvcConfigurer
addCorsMappings
public void addCorsMappings(CorsRegistry registry)
Configure cross origin requests processing.This implementation is empty.
- Specified by:
addCorsMappingsin interfaceWebMvcConfigurer
addViewControllers
public void addViewControllers(ViewControllerRegistry registry)
Configure simple automated controllers pre-configured with the response status code and/or a view to render the response body. This is useful in cases where there is no need for custom controller logic -- e.g. render a home page, perform simple site URL redirects, return a 404 status with HTML content, a 204 with no content, and more.This implementation is empty.
- Specified by:
addViewControllersin interfaceWebMvcConfigurer
configureViewResolvers
public void configureViewResolvers(ViewResolverRegistry registry)
Configure view resolvers to translate String-based view names returned from controllers into concreteViewimplementations to perform rendering with.This implementation is empty.
- Specified by:
configureViewResolversin interfaceWebMvcConfigurer
addArgumentResolvers
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
Add resolvers to support custom controller method argument types.This does not override the built-in support for resolving handler method arguments. To customize the built-in support for argument resolution, configure
RequestMappingHandlerAdapterdirectly.This implementation is empty.
- Specified by:
addArgumentResolversin interfaceWebMvcConfigurer- Parameters:
argumentResolvers- initially an empty list
addReturnValueHandlers
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
Add handlers to support custom controller method return value types.Using this option does not override the built-in support for handling return values. To customize the built-in support for handling return values, configure RequestMappingHandlerAdapter directly.
This implementation is empty.
- Specified by:
addReturnValueHandlersin interfaceWebMvcConfigurer- Parameters:
returnValueHandlers- initially an empty list
configureMessageConverters
public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
Configure theHttpMessageConverters to use for reading or writing to the body of the request or response. If no converters are added, a default list of converters is registered.Note that adding converters to the list, turns off default converter registration. To simply add a converter without impacting default registration, consider using the method
WebMvcConfigurer.extendMessageConverters(java.util.List)instead.This implementation is empty.
- Specified by:
configureMessageConvertersin interfaceWebMvcConfigurer- Parameters:
converters- initially an empty list of converters
extendMessageConverters
public void extendMessageConverters(List<HttpMessageConverter<?>> converters)
A hook for extending or modifying the list of converters after it has been configured. This may be useful for example to allow default converters to be registered and then insert a custom converter through this method.This implementation is empty.
- Specified by:
extendMessageConvertersin interfaceWebMvcConfigurer- Parameters:
converters- the list of configured converters to extend.
configureHandlerExceptionResolvers
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Configure exception resolvers.The given list starts out empty. If it is left empty, the framework configures a default set of resolvers, see
WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(List). Or if any exception resolvers are added to the list, then the application effectively takes over and must provide, fully initialized, exception resolvers.Alternatively you can use
WebMvcConfigurer.extendHandlerExceptionResolvers(List)which allows you to extend or modify the list of exception resolvers configured by default.This implementation is empty.
- Specified by:
configureHandlerExceptionResolversin interfaceWebMvcConfigurer- Parameters:
exceptionResolvers- initially an empty list- See Also:
WebMvcConfigurer.extendHandlerExceptionResolvers(List),WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(List)
extendHandlerExceptionResolvers
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Extending or modify the list of exception resolvers configured by default. This can be useful for inserting a custom exception resolver without interfering with default ones.This implementation is empty.
- Specified by:
extendHandlerExceptionResolversin interfaceWebMvcConfigurer- Parameters:
exceptionResolvers- the list of configured resolvers to extend- See Also:
WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(List)
getValidator
public Validator getValidator()
Provide a customValidatorinstead of the one created by default. The default implementation, assuming JSR-303 is on the classpath, is:OptionalValidatorFactoryBean. Leave the return value asnullto keep the default.This implementation returns
null.- Specified by:
getValidatorin interfaceWebMvcConfigurer
getMessageCodesResolver
public MessageCodesResolver getMessageCodesResolver()
Provide a customMessageCodesResolverfor building message codes from data binding and validation error codes. Leave the return value asnullto keep the default.This implementation returns
null.- Specified by:
getMessageCodesResolverin interfaceWebMvcConfigurer