org.springframework.web.servlet.config.annotation
Interface WebMvcConfigurer

All Known Implementing Classes:
WebMvcConfigurerAdapter

public interface WebMvcConfigurer

Defines options for customizing or adding to the default Spring MVC configuration enabled through the use of @EnableWebMvc. The @Configuration class annotated with @EnableWebMvc is the most obvious place to implement this interface. However all @Configuration classes and more generally all Spring beans that implement this interface will be detected at startup and given a chance to customize Spring MVC configuration provided it is enabled through @EnableWebMvc.

Implementations of this interface will find it convenient to extend WebMvcConfigurerAdapter that provides default method implementations and allows overriding only methods of interest.

Since:
3.1
Author:
Rossen Stoyanchev, Keith Donald, David Syer

Method Summary
 void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
          Add custom HandlerMethodArgumentResolvers to use in addition to the ones registered by default.
 void addFormatters(FormatterRegistry registry)
          Add Converters and Formatters in addition to the ones registered by default.
 void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
          Add custom HandlerMethodReturnValueHandlers to in addition to the ones registered by default.
 void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
          Configure a handler for delegating unhandled requests by forwarding to the Servlet container's default servlet.
 void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
          Configure the list of HandlerExceptionResolvers to use for handling unresolved controller exceptions.
 void configureInterceptors(InterceptorConfigurer configurer)
          Configure the Spring MVC interceptors to use.
 void configureMessageConverters(List<HttpMessageConverter<?>> converters)
          Configure the list of HttpMessageConverters to use when resolving method arguments or handling return values in @RequestMapping and @ExceptionHandler methods.
 void configureResourceHandling(ResourceConfigurer configurer)
          Configure a handler for serving static resources such as images, js, and, css files through Spring MVC including setting cache headers optimized for efficient loading in a web browser.
 void configureViewControllers(ViewControllerConfigurer configurer)
          Configure the view controllers to use.
 Validator getValidator()
          Provide a custom Validator type replacing the one that would be created by default otherwise.
 

Method Detail

addFormatters

void addFormatters(FormatterRegistry registry)
Add Converters and Formatters in addition to the ones registered by default.


configureMessageConverters

void configureMessageConverters(List<HttpMessageConverter<?>> converters)
Configure the list of HttpMessageConverters to use when resolving method arguments or handling return values in @RequestMapping and @ExceptionHandler methods. Specifying custom converters overrides the converters registered by default.

Parameters:
converters - a list to add message converters to

getValidator

Validator getValidator()
Provide a custom Validator type replacing the one that would be created by default otherwise. If this method returns null, and assuming a JSR-303 implementation is available on the classpath, a validator of type LocalValidatorFactoryBean is created by default.


addArgumentResolvers

void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
Add custom HandlerMethodArgumentResolvers to use in addition to the ones registered by default.

Generally custom argument resolvers are invoked first. However this excludes default argument resolvers that rely on the presence of annotations (e.g. @RequestParameter, @PathVariable, etc.). Those argument resolvers are not customizable without configuring RequestMappingHandlerAdapter directly.

Parameters:
argumentResolvers - the list of custom converters, initially empty

addReturnValueHandlers

void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
Add custom HandlerMethodReturnValueHandlers to in addition to the ones registered by default.

Generally custom return value handlers are invoked first. However this excludes default return value handlers that rely on the presence of annotations (e.g. @ResponseBody, @ModelAttribute, etc.). Those handlers are not customizable without configuring RequestMappingHandlerAdapter directly.

Parameters:
returnValueHandlers - the list of custom handlers, initially empty

configureHandlerExceptionResolvers

void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Configure the list of HandlerExceptionResolvers to use for handling unresolved controller exceptions. Specifying exception resolvers overrides the ones registered by default.

Parameters:
exceptionResolvers - a list to add exception resolvers to

configureInterceptors

void configureInterceptors(InterceptorConfigurer configurer)
Configure the Spring MVC interceptors to use. Interceptors can be of type HandlerInterceptor or WebRequestInterceptor. They allow requests to be pre/post processed before/after controller invocation. Interceptors can be registered to apply to all requests or limited to a set of path patterns.

See Also:
InterceptorConfigurer

configureViewControllers

void configureViewControllers(ViewControllerConfigurer configurer)
Configure the view controllers to use. A view controller is used to map a URL path directly to a view name. This is convenient when a request does not require controller logic.


configureResourceHandling

void configureResourceHandling(ResourceConfigurer configurer)
Configure a handler for serving static resources such as images, js, and, css files through Spring MVC including setting cache headers optimized for efficient loading in a web browser. Resources can be served out of locations under web application root, from the classpath, and others.


configureDefaultServletHandling

void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
Configure a handler for delegating unhandled requests by forwarding to the Servlet container's default servlet. This is commonly used when the DispatcherServlet is mapped to "/", which results in cleaner URLs (without a servlet prefix) but may need to still allow some requests (e.g. static resources) to be handled by the Servlet container's default servlet.