Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.config.annotation

public Class WebMvcConfigurationSupport

extends Object
implements ApplicationContextAware, ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
Known Direct Subclasses
org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
Imports
java.util.ArrayList, .Collections, .HashMap, .List, .Locale, .Map, jakarta.servlet.ServletContext, org.springframework.beans.factory.BeanFactoryUtils, .BeanInitializationException, org.springframework.beans.factory.annotation.Qualifier, org.springframework.context.ApplicationContext, .ApplicationContextAware, org.springframework.context.annotation.Bean, .Configuration, .Lazy, org.springframework.core.convert.converter.Converter, org.springframework.format.Formatter, .FormatterRegistry, org.springframework.format.support.DefaultFormattingConversionService, .FormattingConversionService, org.springframework.http.MediaType, org.springframework.http.converter.ByteArrayHttpMessageConverter, .HttpMessageConverter, .ResourceHttpMessageConverter, .ResourceRegionHttpMessageConverter, .StringHttpMessageConverter, org.springframework.http.converter.cbor.KotlinSerializationCborHttpMessageConverter, .MappingJackson2CborHttpMessageConverter, org.springframework.http.converter.feed.AtomFeedHttpMessageConverter, .RssChannelHttpMessageConverter, org.springframework.http.converter.json.GsonHttpMessageConverter, .Jackson2ObjectMapperBuilder, .JsonbHttpMessageConverter, .KotlinSerializationJsonHttpMessageConverter, .MappingJackson2HttpMessageConverter, org.springframework.http.converter.protobuf.KotlinSerializationProtobufHttpMessageConverter, org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter, .MappingJackson2XmlHttpMessageConverter, org.springframework.lang.Nullable, org.springframework.util.AntPathMatcher, .Assert, .ClassUtils, .PathMatcher, org.springframework.validation.Errors, .MessageCodesResolver, .Validator, org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean, org.springframework.web.HttpRequestHandler, org.springframework.web.accept.ContentNegotiationManager, org.springframework.web.bind.WebDataBinder, org.springframework.web.bind.support.ConfigurableWebBindingInitializer, org.springframework.web.context.ServletContextAware, org.springframework.web.cors.CorsConfiguration, org.springframework.web.method.support.CompositeUriComponentsContributor, .HandlerMethodArgumentResolver, .HandlerMethodReturnValueHandler, org.springframework.web.servlet.FlashMapManager, .HandlerAdapter, .HandlerExceptionResolver, .HandlerMapping, .LocaleResolver, .RequestToViewNameTranslator, .ViewResolver, org.springframework.web.servlet.function.support.HandlerFunctionAdapter, .RouterFunctionMapping, org.springframework.web.servlet.handler.AbstractHandlerMapping, .BeanNameUrlHandlerMapping, .ConversionServiceExposingInterceptor, .HandlerExceptionResolverComposite, .HandlerMappingIntrospector, org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver, org.springframework.web.servlet.mvc.Controller, .HttpRequestHandlerAdapter, .SimpleControllerHandlerAdapter, org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver, org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver, .JsonViewRequestBodyAdvice, .JsonViewResponseBodyAdvice, .RequestMappingHandlerAdapter, .RequestMappingHandlerMapping, org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver, org.springframework.web.servlet.resource.ResourceUrlProvider, .ResourceUrlProviderExposingInterceptor, org.springframework.web.servlet.support.SessionFlashMapManager, org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator, .InternalResourceViewResolver, .ViewResolverComposite, org.springframework.web.util.UrlPathHelper, org.springframework.web.util.pattern.PathPatternParser

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:

Authors
Rossen Stoyanchev, Brian Clozel, Sebastien Deleuze
Since
3.1
See Also
EnableWebMvc, WebMvcConfigurer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ApplicationContext
private List<HandlerMethodArgumentResolver>
private AsyncSupportConfigurer
private ContentNegotiationManager
private Map<String, CorsConfiguration>
private static final boolean
private List<Object>
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private List<HttpMessageConverter<?>>
private PathMatchConfigurer
private List<HandlerMethodReturnValueHandler>
private static final boolean
private ServletContext

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
addArgumentResolvers(List<HandlerMethodArgumentResolver>
the list of custom converters (initially an empty list)
argumentResolvers
)

Add custom HandlerMethodArgumentResolvers to use in addition to the ones registered by default.

protected void
addCorsMappings(CorsRegistry registry)

Override this method to configure cross-origin requests processing.

protected final void
addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers, ContentNegotiationManager mvcContentNegotiationManager)

A method available to subclasses for adding default HandlerExceptionResolvers.

protected final void
addDefaultHttpMessageConverters(List<HttpMessageConverter<?>>
the list to add the default message converters to
messageConverters
)

Adds a set of default HttpMessageConverter instances to the given list.

protected void
addFormatters(FormatterRegistry registry)

Override this method to add custom Converter and/or Formatter delegates to the common FormattingConversionService.

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(List<HandlerMethodReturnValueHandler>
the list of custom handlers (initially an empty list)
returnValueHandlers
)

Add custom HandlerMethodReturnValueHandlers in addition to the ones registered by default.

protected void
addViewControllers(ViewControllerRegistry registry)

Override this method to add view controllers.

public BeanNameUrlHandlerMapping
beanNameHandlerMapping(FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider)

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

protected void
configureAsyncSupport(AsyncSupportConfigurer configurer)

Override this method to configure asynchronous request processing options.

protected void
configureContentNegotiation(ContentNegotiationConfigurer configurer)

Override this method to configure content negotiation.

protected void
configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)

Override this method to configure "default" Servlet handling.

protected void
configureHandlerExceptionResolvers(List<HandlerExceptionResolver>
a list to add exception resolvers to (initially an empty list)
exceptionResolvers
)

Override this method to configure the list of HandlerExceptionResolvers to use.

protected void
configureMessageConverters(List<HttpMessageConverter<?>>
a list to add message converters to (initially an empty list)
converters
)

Override this method to add custom HttpMessageConverters to use with the RequestMappingHandlerAdapter and the ExceptionHandlerExceptionResolver.

protected void
configurePathMatch(PathMatchConfigurer configurer)

Override this method to configure path matching options.

protected void
configureViewResolvers(ViewResolverRegistry registry)

Override this method to configure view resolution.

protected ExceptionHandlerExceptionResolver
createExceptionHandlerExceptionResolver()

Protected method for plugging in a custom subclass of ExceptionHandlerExceptionResolver.

protected RequestMappingHandlerAdapter
createRequestMappingHandlerAdapter()

Protected method for plugging in a custom subclass of RequestMappingHandlerAdapter.

protected RequestMappingHandlerMapping
createRequestMappingHandlerMapping()

Protected method for plugging in a custom subclass of RequestMappingHandlerMapping.

public HandlerMapping
defaultServletHandlerMapping()

Return a handler mapping ordered at Integer.MAX_VALUE with a mapped default servlet handler.

protected void
extendHandlerExceptionResolvers(List<HandlerExceptionResolver>
the list of configured resolvers to extend.
exceptionResolvers
)

Override this method to extend or modify the list of HandlerExceptionResolvers after it has been configured.

protected void
extendMessageConverters(List<HttpMessageConverter<?>>
the list of configured converters to extend
converters
)

Override this method to extend or modify the list of converters after it has been configured.

public FlashMapManager
public final ApplicationContext
getApplicationContext()

Return the associated Spring ApplicationContext.

protected final List<HandlerMethodArgumentResolver>
getArgumentResolvers()

Provide access to the shared custom argument resolvers used by the RequestMappingHandlerAdapter and the ExceptionHandlerExceptionResolver.

protected AsyncSupportConfigurer
protected ConfigurableWebBindingInitializer
getConfigurableWebBindingInitializer(FormattingConversionService mvcConversionService, Validator mvcValidator)

Return the ConfigurableWebBindingInitializer to use for initializing all WebDataBinder instances.

protected final Map<String, CorsConfiguration>
getCorsConfigurations()

Return the registered CorsConfiguration objects, keyed by path pattern.

protected Map<String, MediaType>
protected final Object[]
getInterceptors(FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider)

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 final List<HttpMessageConverter<?>>
protected PathMatchConfigurer
getPathMatchConfigurer()

Callback for building the PathMatchConfigurer.

protected final List<HandlerMethodReturnValueHandler>
getReturnValueHandlers()

Provide access to the shared return value handlers used by the RequestMappingHandlerAdapter and the ExceptionHandlerExceptionResolver.

public final ServletContext
protected Validator
getValidator()

Override this method to provide a custom Validator.

public HandlerExceptionResolver
handlerExceptionResolver(ContentNegotiationManager contentNegotiationManager)

Returns a HandlerExceptionResolverComposite containing a list of exception resolvers obtained either through configureHandlerExceptionResolvers or through addDefaultHandlerExceptionResolvers.

public HandlerFunctionAdapter
handlerFunctionAdapter()

Returns a HandlerFunctionAdapter for processing requests through handler functions.

public HttpRequestHandlerAdapter
private void
public LocaleResolver
public ContentNegotiationManager
mvcContentNegotiationManager()

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

public FormattingConversionService
mvcConversionService()

Return a FormattingConversionService for use with annotated controllers.

public HandlerMappingIntrospector
public PathMatcher
mvcPathMatcher()

Return a global PathMatcher instance which is used for URL path matching with String patterns.

public PathPatternParser
mvcPatternParser()

Return a global PathPatternParser instance to use for parsing patterns to match to the org.springframework.http.server.RequestPath.

public ResourceUrlProvider
mvcResourceUrlProvider()

A ResourceUrlProvider bean for use with the MVC dispatcher.

public CompositeUriComponentsContributor
public UrlPathHelper
mvcUrlPathHelper()

Return a global UrlPathHelper instance which is used to resolve the request mapping path for an application.

public Validator
mvcValidator()

Return a global Validator instance for example for validating @ModelAttribute and @RequestBody method arguments.

public ViewResolver
mvcViewResolver(ContentNegotiationManager contentNegotiationManager)

Register a ViewResolverComposite that contains a chain of view resolvers to use for view resolution.

public RequestMappingHandlerAdapter
requestMappingHandlerAdapter(ContentNegotiationManager contentNegotiationManager, FormattingConversionService conversionService, Validator validator)

Returns a RequestMappingHandlerAdapter for processing requests through annotated controller methods.

public RequestMappingHandlerMapping
requestMappingHandlerMapping(ContentNegotiationManager contentNegotiationManager, FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider)

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

public HandlerMapping
resourceHandlerMapping(ContentNegotiationManager contentNegotiationManager, FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider)

Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped resource handlers.

public RouterFunctionMapping
routerFunctionMapping(FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider)

Return a RouterFunctionMapping ordered at -1 to map router functions.

public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

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

public void
setServletContext(ServletContext
the ServletContext object to be used by this object
servletContext
)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

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

public SimpleControllerHandlerAdapter
simpleControllerHandlerAdapter()

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

public ThemeResolver
themeResolver()
Deprecated

public HandlerMapping
viewControllerHandlerMapping(FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider)

Return a handler mapping ordered at 1 to map URL paths directly to view names.

public RequestToViewNameTranslator
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait