public interface WebMvcConfigurer
@EnableWebMvc
.
@EnableWebMvc
-annotated configuration classes may implement
this interface to be called back and given a chance to customize the
default configuration. Consider extending WebMvcConfigurerAdapter
,
which provides a stub implementation of all interface methods.
Modifier and Type | Method and Description |
---|---|
void |
addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
Add resolvers to support custom controller method argument types.
|
void |
addCorsMappings(CorsRegistry registry)
Configure cross origin requests processing.
|
void |
addFormatters(FormatterRegistry registry)
|
void |
addInterceptors(InterceptorRegistry registry)
Add Spring MVC lifecycle interceptors for pre- and post-processing of
controller method invocations.
|
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.
|
void |
addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
Add handlers to support custom controller method return value types.
|
void |
addViewControllers(ViewControllerRegistry registry)
Configure simple automated controllers pre-configured with the response
status code and/or a view to render the response body.
|
void |
configureAsyncSupport(AsyncSupportConfigurer configurer)
Configure asynchronous request handling options.
|
void |
configureContentNegotiation(ContentNegotiationConfigurer configurer)
Configure content negotiation options.
|
void |
configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
Configure a handler to delegate unhandled requests by forwarding to the
Servlet container's "default" servlet.
|
void |
configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Configure exception resolvers.
|
void |
configureMessageConverters(List<HttpMessageConverter<?>> converters)
Configure the
HttpMessageConverter s to use for reading or writing
to the body of the request or response. |
void |
configurePathMatch(PathMatchConfigurer configurer)
Helps with configuring HandlerMappings path matching options such as trailing slash match,
suffix registration, path matcher and path helper.
|
void |
configureViewResolvers(ViewResolverRegistry registry)
Configure view resolvers to translate String-based view names returned from
controllers into concrete
View
implementations to perform rendering with. |
void |
extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Extending or modify the list of exception resolvers configured by default.
|
void |
extendMessageConverters(List<HttpMessageConverter<?>> converters)
A hook for extending or modifying the list of converters after it has been
configured.
|
MessageCodesResolver |
getMessageCodesResolver()
Provide a custom
MessageCodesResolver for building message codes
from data binding and validation error codes. |
Validator |
getValidator()
Provide a custom
Validator instead of the one created by default. |
void configurePathMatch(PathMatchConfigurer configurer)
void configureContentNegotiation(ContentNegotiationConfigurer configurer)
void configureAsyncSupport(AsyncSupportConfigurer configurer)
void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
DispatcherServlet
is mapped to "/" thus overriding the
Servlet container's default handling of static resources.void addFormatters(FormatterRegistry registry)
void addInterceptors(InterceptorRegistry registry)
Note that interceptors registered here only apply to
controllers and not to resource handler requests. To intercept requests for
static resources either declare a
MappedInterceptor
bean or switch to advanced configuration mode by extending
WebMvcConfigurationSupport
and then override resourceHandlerMapping
.
void addResourceHandlers(ResourceHandlerRegistry registry)
void addCorsMappings(CorsRegistry registry)
void addViewControllers(ViewControllerRegistry registry)
void configureViewResolvers(ViewResolverRegistry registry)
View
implementations to perform rendering with.void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
This does not override the built-in support for resolving handler
method arguments. To customize the built-in support for argument
resolution, configure RequestMappingHandlerAdapter
directly.
argumentResolvers
- initially an empty listvoid addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
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.
returnValueHandlers
- initially an empty listvoid configureMessageConverters(List<HttpMessageConverter<?>> converters)
HttpMessageConverter
s 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
extendMessageConverters(java.util.List)
instead.
converters
- initially an empty list of convertersvoid extendMessageConverters(List<HttpMessageConverter<?>> converters)
converters
- the list of configured converters to extend.void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
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
extendHandlerExceptionResolvers(List)
which allows you to extend
or modify the list of exception resolvers configured by default.
exceptionResolvers
- initially an empty listextendHandlerExceptionResolvers(List)
,
WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(List)
void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
exceptionResolvers
- the list of configured resolvers to extendWebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(List)
Validator getValidator()
Validator
instead of the one created by default.
The default implementation, assuming JSR-303 is on the classpath, is:
OptionalValidatorFactoryBean
.
Leave the return value as null
to keep the default.MessageCodesResolver getMessageCodesResolver()
MessageCodesResolver
for building message codes
from data binding and validation error codes. Leave the return value as
null
to keep the default.