spring-framework / org.springframework.web.servlet.config.annotation / WebMvcConfigurationSupport

WebMvcConfigurationSupport

open class WebMvcConfigurationSupport : 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 HandlerMappings:

Registers these HandlerAdapters:

Registers a HandlerExceptionResolverComposite with this chain of exception resolvers:

Registers an AntPathMatcher and a UrlPathHelper to be used by:

Note that those beans can be configured with a PathMatchConfigurer.

Both the RequestMappingHandlerAdapter and the ExceptionHandlerExceptionResolver are configured with default instances of the following by default:

Author
Rossen Stoyanchev

Author
Brian Clozel

Author
Sebastien Deleuze

Since
3.1

See Also
EnableWebMvcWebMvcConfigurer

Constructors

<init>

WebMvcConfigurationSupport()

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 HandlerMappings:

  • 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 HandlerAdapters:

  • RequestMappingHandlerAdapter for processing requests with annotated controller methods.
  • HttpRequestHandlerAdapter for processing requests with HttpRequestHandlers.
  • SimpleControllerHandlerAdapter for processing requests with interface-based Controllers.

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

Registers an AntPathMatcher and a UrlPathHelper to be used by:

  • the RequestMappingHandlerMapping,
  • the HandlerMapping for ViewControllers
  • and the HandlerMapping for serving resources
Note that those beans can be configured with a PathMatchConfigurer.

Both the RequestMappingHandlerAdapter and the ExceptionHandlerExceptionResolver are configured with default instances of the following by default:

  • a ContentNegotiationManager
  • a DefaultFormattingConversionService
  • a org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean if a JSR-303 implementation is available on the classpath
  • a range of HttpMessageConverters depending on the third-party libraries available on the classpath.

Functions

beanNameHandlerMapping

open fun beanNameHandlerMapping(): BeanNameUrlHandlerMapping

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

defaultServletHandlerMapping

open fun defaultServletHandlerMapping(): HandlerMapping

Return a handler mapping ordered at Integer.MAX_VALUE with a mapped default servlet handler. To configure "default" Servlet handling, override #configureDefaultServletHandling.

getApplicationContext

fun getApplicationContext(): ApplicationContext

Return the associated Spring ApplicationContext.

getServletContext

fun getServletContext(): ServletContext

Return the associated javax.servlet.ServletContext.

handlerExceptionResolver

open fun 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.

httpRequestHandlerAdapter

open fun httpRequestHandlerAdapter(): HttpRequestHandlerAdapter

Returns a HttpRequestHandlerAdapter for processing requests with HttpRequestHandlers.

mvcContentNegotiationManager

open fun mvcContentNegotiationManager(): ContentNegotiationManager

Return a ContentNegotiationManager instance to use to determine requested MediaType in a given request.

mvcConversionService

open fun mvcConversionService(): FormattingConversionService

Return a FormattingConversionService for use with annotated controller methods and the spring:eval JSP tag. Also see #addFormatters as an alternative to overriding this method.

mvcHandlerMappingIntrospector

open fun mvcHandlerMappingIntrospector(): HandlerMappingIntrospector

mvcPathMatcher

open fun mvcPathMatcher(): PathMatcher

Return a global PathMatcher instance for path matching patterns in HandlerMappings. This instance can be configured using the PathMatchConfigurer in #configurePathMatch(PathMatchConfigurer).

mvcResourceUrlProvider

open fun mvcResourceUrlProvider(): ResourceUrlProvider

A ResourceUrlProvider bean for use with the MVC dispatcher.

mvcUriComponentsContributor

open fun mvcUriComponentsContributor(): CompositeUriComponentsContributor

Return an instance of CompositeUriComponentsContributor for use with org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.

mvcUrlPathHelper

open fun mvcUrlPathHelper(): UrlPathHelper

Return a global UrlPathHelper instance for path matching patterns in HandlerMappings. This instance can be configured using the PathMatchConfigurer in #configurePathMatch(PathMatchConfigurer).

mvcValidator

open fun mvcValidator(): Validator

Return 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 OptionalValidatorFactoryBean.If a JSR-303 implementation is not available, a no-op Validator is returned.

mvcViewResolver

open fun mvcViewResolver(): ViewResolver

Register a ViewResolverComposite that contains a chain of view resolvers to use for view resolution. By default this resolver is ordered at 0 unless content negotiation view resolution is used in which case the order is raised to Ordered.HIGHEST_PRECEDENCE.

If no other resolvers are configured, ViewResolverComposite#resolveViewName(String, Locale) returns null in order to allow other potential ViewResolver beans to resolve views.

requestMappingHandlerAdapter

open fun requestMappingHandlerAdapter(): RequestMappingHandlerAdapter

Returns a RequestMappingHandlerAdapter for processing requests through annotated controller methods. Consider overriding one of these other more fine-grained methods:

requestMappingHandlerMapping

open fun requestMappingHandlerMapping(): RequestMappingHandlerMapping

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

resourceHandlerMapping

open fun resourceHandlerMapping(): HandlerMapping

Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped resource handlers. To configure resource handling, override #addResourceHandlers.

setApplicationContext

open fun setApplicationContext(applicationContext: ApplicationContext): Unit

Set the Spring ApplicationContext, e.g. for resource loading.

setServletContext

open fun setServletContext(servletContext: ServletContext): Unit

Set the javax.servlet.ServletContext, e.g. for resource handling, looking up file extensions, etc.

simpleControllerHandlerAdapter

open fun simpleControllerHandlerAdapter(): SimpleControllerHandlerAdapter

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

viewControllerHandlerMapping

open fun viewControllerHandlerMapping(): HandlerMapping

Return a handler mapping ordered at 1 to map URL paths directly to view names. To configure view controllers, override #addViewControllers.