Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.servlet.config.annotation
Class WebMvcConfigurationSupport

    java.lang.Object
      org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport

All Implemented Interfaces:
  Aware, ApplicationContextAware, ServletContextAware

Direct Known Subclasses:
  DelegatingWebMvcConfiguration

    public class WebMvcConfigurationSupport

extends java.lang.Object
implements ApplicationContextAware, ServletContextAware

This is the main class providing the configuration behind the MVC Java config. It is typically imported by adding `@EnableWebMvc` to an application `@Configuration` class. An alternative more advanced option is to extend directly from this class and override methods as necessary remembering to add `@Configuration` to the subclass and `@Bean` to overridden `@Bean` methods. For more details see the Javadoc of `@EnableWebMvc`.

This class registers the following `HandlerMapping`s:

- `RequestMappingHandlerMapping` ordered at 0 for mapping requests to annotated controller methods.
- `HandlerMapping` ordered at 1 to map URL paths directly to view names.
- `BeanNameUrlHandlerMapping` ordered at 2 to map URL paths to controller bean names.
- `HandlerMapping` ordered at `Integer.MAX_VALUE-1` to serve static resource requests.
- `HandlerMapping` ordered at `Integer.MAX_VALUE` to forward requests to the default servlet.

Registers these `HandlerAdapter`s:

- `RequestMappingHandlerAdapter` for processing requests with annotated controller methods.
- `HttpRequestHandlerAdapter` for processing requests with `HttpRequestHandler`s.
- `SimpleControllerHandlerAdapter` for processing requests with interface-based `Controller`s.

Registers a `HandlerExceptionResolverComposite` with this chain of exception resolvers:

- `ExceptionHandlerExceptionResolver` for handling exceptions through @`ExceptionHandler` methods.
- `ResponseStatusExceptionResolver` for exceptions annotated with @`ResponseStatus`.
- `DefaultHandlerExceptionResolver` for resolving known Spring exception types

Both the `RequestMappingHandlerAdapter` and the `ExceptionHandlerExceptionResolver` are configured with default instances of the following kind, unless custom instances are provided:

- A `DefaultFormattingConversionService`
- A `LocalValidatorFactoryBean` if a JSR-303 implementation is available on the classpath
- A range of `HttpMessageConverter`s depending on the 3rd party libraries available on the classpath.

Since:
  3.1
Author:
  Rossen Stoyanchev
See Also:
  `EnableWebMvc`, `WebMvcConfigurer`, `WebMvcConfigurerAdapter`

Constructor Summary
`WebMvcConfigurationSupport()`

Method Summary
`protected void` | `addArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)` Add custom `HandlerMethodArgumentResolver`s to use in addition to the ones registered by default.
`protected void` | `addDefaultHandlerExceptionResolvers(java.util.List<HandlerExceptionResolver> exceptionResolvers)` A method available to subclasses for adding default `HandlerExceptionResolver`s.
`protected void` | `addDefaultHttpMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)` Adds a set of default HttpMessageConverter instances to the given list.
`protected void` | `addFormatters(FormatterRegistry registry)` Override this method to add custom `Converter`s and `Formatter`s.
`protected void` | `addInterceptors(InterceptorRegistry registry)` Override this method to add Spring MVC interceptors for pre- and post-processing of controller invocation.
`protected void` | `addResourceHandlers(ResourceHandlerRegistry registry)` Override this method to add resource handlers for serving static resources.
`protected void` | `addReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)` Add custom `HandlerMethodReturnValueHandler`s in addition to the ones registered by default.
`protected void` | `addViewControllers(ViewControllerRegistry registry)` Override this method to add view controllers.
`BeanNameUrlHandlerMapping` | `beanNameHandlerMapping()` Return a `BeanNameUrlHandlerMapping` ordered at 2 to map URL paths to controller bean names.
`protected void` | `configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)` Override this method to configure "default" Servlet handling.
`protected void` | `configureHandlerExceptionResolvers(java.util.List<HandlerExceptionResolver> exceptionResolvers)` Override this method to configure the list of `HandlerExceptionResolver`s to use.
`protected void` | `configureMessageConverters(java.util.List<HttpMessageConverter<?>> converters)` Override this method to add custom `HttpMessageConverter`s to use with the `RequestMappingHandlerAdapter` and the `ExceptionHandlerExceptionResolver`.
`HandlerMapping` | `defaultServletHandlerMapping()` Return a handler mapping ordered at Integer.MAX_VALUE with a mapped default servlet handler.
`protected java.lang.Object[]` | `getInterceptors()` Provide access to the shared handler interceptors used to configure `HandlerMapping` instances with.
`protected MessageCodesResolver` | `getMessageCodesResolver()` Override this method to provide a custom `MessageCodesResolver`.
`protected java.util.List<HttpMessageConverter<?>>` | `getMessageConverters()` Provides access to the shared `HttpMessageConverter`s used by the `RequestMappingHandlerAdapter` and the `ExceptionHandlerExceptionResolver`.
`protected Validator` | `getValidator()` Override this method to provide a custom `Validator`.
`HandlerExceptionResolver` | `handlerExceptionResolver()` Returns a `HandlerExceptionResolverComposite` containing a list of exception resolvers obtained either through `configureHandlerExceptionResolvers(List)` or through `addDefaultHandlerExceptionResolvers(List)`.
`HttpRequestHandlerAdapter` | `httpRequestHandlerAdapter()` Returns a `HttpRequestHandlerAdapter` for processing requests with `HttpRequestHandler`s.
`FormattingConversionService` | `mvcConversionService()` Returns a `FormattingConversionService` for use with annotated controller methods and the `spring:eval` JSP tag.
`Validator` | `mvcValidator()` Returns a global `Validator` instance for example for validating `@ModelAttribute` and `@RequestBody` method arguments.
`RequestMappingHandlerAdapter` | `requestMappingHandlerAdapter()` Returns a `RequestMappingHandlerAdapter` for processing requests through annotated controller methods.
`RequestMappingHandlerMapping` | `requestMappingHandlerMapping()` Return a `RequestMappingHandlerMapping` ordered at 0 for mapping requests to annotated controllers.
`HandlerMapping` | `resourceHandlerMapping()` Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped resource handlers.
`void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.
`void` | `setServletContext(javax.servlet.ServletContext servletContext)` Set the ServletContext that this object runs in.
`SimpleControllerHandlerAdapter` | `simpleControllerHandlerAdapter()` Returns a `SimpleControllerHandlerAdapter` for processing requests with interface-based controllers.
`HandlerMapping` | `viewControllerHandlerMapping()` Return a handler mapping ordered at 1 to map URL paths directly to view names.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### WebMvcConfigurationSupport

    public WebMvcConfigurationSupport()

Method Detail

### setServletContext

    public void setServletContext(javax.servlet.ServletContext servletContext)

  Description copied from interface: `ServletContextAware`
  Set the ServletContext that this object runs in.

  Invoked after population of normal bean properties but before an init callback like InitializingBean's `afterPropertiesSet` or a custom init-method. Invoked after ApplicationContextAware's `setApplicationContext`.

  Specified by:
    `setServletContext` in interface `ServletContextAware`
  Parameters:
    `servletContext` - ServletContext object to be used by this object
  See Also:
    `InitializingBean.afterPropertiesSet()`, `ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)`

### setApplicationContext

    public void setApplicationContext(ApplicationContext applicationContext)
                               throws BeansException

  Description copied from interface: `ApplicationContextAware`
  Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

  Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

  Specified by:
    `setApplicationContext` in interface `ApplicationContextAware`
  Parameters:
    `applicationContext` - the ApplicationContext object to be used by this object
  Throws:
    `ApplicationContextException` - in case of context initialization errors
    `BeansException` - if thrown by application context methods
  See Also:
    `BeanInitializationException`

### requestMappingHandlerMapping

    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping()

  Return a `RequestMappingHandlerMapping` ordered at 0 for mapping requests to annotated controllers.

### getInterceptors

    protected final java.lang.Object[] getInterceptors()

  Provide access to the shared handler interceptors used to configure `HandlerMapping` instances with. This method cannot be overridden, use `addInterceptors(InterceptorRegistry)` instead.

### addInterceptors

    protected void addInterceptors(InterceptorRegistry registry)

  Override this method to add Spring MVC interceptors for pre- and post-processing of controller invocation.

  See Also:
    `InterceptorRegistry`

### viewControllerHandlerMapping

    @Bean
    public HandlerMapping viewControllerHandlerMapping()

  Return a handler mapping ordered at 1 to map URL paths directly to view names. To configure view controllers, override `addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry)`.

### addViewControllers

    protected void addViewControllers(ViewControllerRegistry registry)

  Override this method to add view controllers.

  See Also:
    `ViewControllerRegistry`

### beanNameHandlerMapping

    @Bean
    public BeanNameUrlHandlerMapping beanNameHandlerMapping()

  Return a `BeanNameUrlHandlerMapping` ordered at 2 to map URL paths to controller bean names.

### resourceHandlerMapping

    @Bean
    public HandlerMapping resourceHandlerMapping()

  Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped resource handlers. To configure resource handling, override `addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry)`.

### addResourceHandlers

    protected void addResourceHandlers(ResourceHandlerRegistry registry)

  Override this method to add resource handlers for serving static resources.

  See Also:
    `ResourceHandlerRegistry`

### defaultServletHandlerMapping

    @Bean
    public HandlerMapping defaultServletHandlerMapping()

  Return a handler mapping ordered at Integer.MAX_VALUE with a mapped default servlet handler. To configure "default" Servlet handling, override `configureDefaultServletHandling(org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer)`.

### configureDefaultServletHandling

    protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)

  Override this method to configure "default" Servlet handling.

  See Also:
    `DefaultServletHandlerConfigurer`

### requestMappingHandlerAdapter

    @Bean
    public RequestMappingHandlerAdapter requestMappingHandlerAdapter()

  Returns a `RequestMappingHandlerAdapter` for processing requests through annotated controller methods. Consider overriding one of these other more fine-grained methods:
  - `addArgumentResolvers(java.util.List)` for adding custom argument resolvers.
  - `addReturnValueHandlers(java.util.List)` for adding custom return value handlers.
  - `configureMessageConverters(java.util.List>)` for adding custom message converters.

### mvcConversionService

    @Bean
    public FormattingConversionService mvcConversionService()

  Returns a `FormattingConversionService` for use with annotated controller methods and the `spring:eval` JSP tag. Also see `addFormatters(org.springframework.format.FormatterRegistry)` as an alternative to overriding this method.

### mvcValidator

    @Bean
    public Validator mvcValidator()

  Returns a global `Validator` instance for example for validating `@ModelAttribute` and `@RequestBody` method arguments. Delegates to `getValidator()` first and if that returns `null` checks the classpath for the presence of a JSR-303 implementations before creating a `LocalValidatorFactoryBean`.If a JSR-303 implementation is not available, a no-op `Validator` is returned.

### getValidator

    protected Validator getValidator()

  Override this method to provide a custom `Validator`.

### getMessageCodesResolver

    protected MessageCodesResolver getMessageCodesResolver()

  Override this method to provide a custom `MessageCodesResolver`.

### addArgumentResolvers

    protected void addArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)

  Add custom `HandlerMethodArgumentResolver`s to use in addition to the ones registered by default.

  Custom argument resolvers are invoked before built-in resolvers except for those that rely on the presence of annotations (e.g. `@RequestParameter`, `@PathVariable`, etc.). The latter can be customized by configuring the `RequestMappingHandlerAdapter` directly.

  Parameters:
    `argumentResolvers` - the list of custom converters; initially an empty list.

### addReturnValueHandlers

    protected void addReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)

  Add custom `HandlerMethodReturnValueHandler`s in addition to the ones registered by default.

  Custom return value handlers are invoked before built-in ones except for those that rely on the presence of annotations (e.g. `@ResponseBody`, `@ModelAttribute`, etc.). The latter can be customized by configuring the `RequestMappingHandlerAdapter` directly.

  Parameters:
    `returnValueHandlers` - the list of custom handlers; initially an empty list.

### getMessageConverters

    protected final java.util.List<HttpMessageConverter<?>> getMessageConverters()

  Provides access to the shared `HttpMessageConverter`s used by the `RequestMappingHandlerAdapter` and the `ExceptionHandlerExceptionResolver`. This method cannot be overridden. Use `configureMessageConverters(List)` instead. Also see `addDefaultHttpMessageConverters(List)` that can be used to add default message converters.

### configureMessageConverters

    protected void configureMessageConverters(java.util.List<HttpMessageConverter<?>> converters)

  Override this method to add custom `HttpMessageConverter`s to use with the `RequestMappingHandlerAdapter` and the `ExceptionHandlerExceptionResolver`. Adding converters to the list turns off the default converters that would otherwise be registered by default. Also see `addDefaultHttpMessageConverters(List)` that can be used to add default message converters.

  Parameters:
    `converters` - a list to add message converters to; initially an empty list.

### addDefaultHttpMessageConverters

    protected final void addDefaultHttpMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)

  Adds a set of default HttpMessageConverter instances to the given list. Subclasses can call this method from `configureMessageConverters(List)`.

  Parameters:
    `messageConverters` - the list to add the default message converters to

### addFormatters

    protected void addFormatters(FormatterRegistry registry)

  Override this method to add custom `Converter`s and `Formatter`s.

### httpRequestHandlerAdapter

    @Bean
    public HttpRequestHandlerAdapter httpRequestHandlerAdapter()

  Returns a `HttpRequestHandlerAdapter` for processing requests with `HttpRequestHandler`s.

### simpleControllerHandlerAdapter

    @Bean
    public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter()

  Returns a `SimpleControllerHandlerAdapter` for processing requests with interface-based controllers.

### handlerExceptionResolver

    @Bean
    public HandlerExceptionResolver handlerExceptionResolver()

  Returns a `HandlerExceptionResolverComposite` containing a list of exception resolvers obtained either through `configureHandlerExceptionResolvers(List)` or through `addDefaultHandlerExceptionResolvers(List)`.

  Note: This method cannot be made final due to CGLib constraints. Rather than overriding it, consider overriding `configureHandlerExceptionResolvers(List)`, which allows providing a list of resolvers.

### configureHandlerExceptionResolvers

    protected void configureHandlerExceptionResolvers(java.util.List<HandlerExceptionResolver> exceptionResolvers)

  Override this method to configure the list of `HandlerExceptionResolver`s to use. Adding resolvers to the list turns off the default resolvers that would otherwise be registered by default. Also see `addDefaultHandlerExceptionResolvers(List)` that can be used to add the default exception resolvers.

  Parameters:
    `exceptionResolvers` - a list to add exception resolvers to; initially an empty list.

### addDefaultHandlerExceptionResolvers

    protected final void addDefaultHandlerExceptionResolvers(java.util.List<HandlerExceptionResolver> exceptionResolvers)

  A method available to subclasses for adding default `HandlerExceptionResolver`s.

  Adds the following exception resolvers:

  - `ExceptionHandlerExceptionResolver` for handling exceptions through @`ExceptionHandler` methods.
  - `ResponseStatusExceptionResolver` for exceptions annotated with @`ResponseStatus`.
  - `DefaultHandlerExceptionResolver` for resolving known Spring exception types

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD