Class AbstractHandlerMapping
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ApplicationContextAware,- Ordered,- ServletContextAware,- HandlerMapping
- Direct Known Subclasses:
- AbstractHandlerMethodMapping,- AbstractUrlHandlerMapping,- RouterFunctionMapping
HandlerMapping
 implementations. Supports ordering, a default handler, handler interceptors,
 including handler interceptors mapped by path patterns.
 Note: This base class does not support exposure of the
 HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE. Support for this attribute
 is up to concrete subclasses, typically based on request URL mappings.
- Since:
- 07.04.2003
- Author:
- Juergen Hoeller, Rossen Stoyanchev, Sam Brannen
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final LogDedicated "hidden" logger for request mappings.Fields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.HandlerMappingBEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected HandlerInterceptoradaptInterceptor(Object interceptor) Adapt the given interceptor object toHandlerInterceptor.protected voiddetectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) Detect beans of typeMappedInterceptorand add them to the list of mapped interceptors.protected voidextendInterceptors(List<Object> interceptors) Extension hook that subclasses can override to register additional interceptors, given the configured interceptors (seesetInterceptors(java.lang.Object...)).protected Stringprotected final HandlerInterceptor[]Return the adapted interceptors asHandlerInterceptorarray.protected CorsConfigurationgetCorsConfiguration(Object handler, HttpServletRequest request) Retrieve the CORS configuration for the given handler.Return theconfiguredCorsConfigurationSource, if any.protected HandlerExecutionChaingetCorsHandlerExecutionChain(HttpServletRequest request, HandlerExecutionChain chain, CorsConfiguration config) Update the HandlerExecutionChain for CORS-related handling.Return the configuredCorsProcessor.Return the default handler for this handler mapping, ornullif none.final HandlerExecutionChaingetHandler(HttpServletRequest request) Look up a handler for the given request, falling back to the default handler if no specific one is found.protected HandlerExecutionChaingetHandlerExecutionChain(Object handler, HttpServletRequest request) Build aHandlerExecutionChainfor the given handler, including applicable interceptors.protected abstract ObjectgetHandlerInternal(HttpServletRequest request) Look up a handler for the given request, returningnullif no specific one is found.protected final MappedInterceptor[]Return all configuredMappedInterceptors as an array.intgetOrder()Get the order value of this object.Return theconfiguredPathMatcher.Return theconfiguredUrlPathHelper.protected booleanhasCorsConfigurationSource(Object handler) Returntrueif there is aCorsConfigurationSourcefor this handler.protected voidInitializes the interceptors.protected voidInitialize the specified interceptors adaptingWebRequestInterceptors toHandlerInterceptor.protected StringinitLookupPath(HttpServletRequest request) Initialize the path to use for request mapping.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath) Shortcut to same property on the configuredUrlPathHelper.voidsetBeanName(String name) Set the name of the bean in the bean factory that created this bean.voidsetCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) Set "global" CORS configuration mappings.voidSet aCorsConfigurationSourcefor "global" CORS config.voidsetCorsProcessor(CorsProcessor corsProcessor) Configure a customCorsProcessorto use to apply the matchedCorsConfigurationfor a request.voidsetDefaultHandler(Object defaultHandler) Set the default handler for this handler mapping.voidsetInterceptors(Object... interceptors) Set the interceptors to apply for all handlers mapped by this handler mapping.voidsetOrder(int order) Specify the order value for this HandlerMapping bean.voidsetPathMatcher(PathMatcher pathMatcher) Configure the PathMatcher to use.voidsetPatternParser(PathPatternParser patternParser) Enable use of pre-parsedPathPatterns as an alternative to String pattern matching withAntPathMatcher.voidsetRemoveSemicolonContent(boolean removeSemicolonContent) Shortcut to same property on the underlyingUrlPathHelper.voidsetUrlDecode(boolean urlDecode) Shortcut to same property on the underlyingUrlPathHelper.voidsetUrlPathHelper(UrlPathHelper urlPathHelper) Configure the UrlPathHelper to use for resolution of lookup paths.booleanMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Field Details- 
mappingsLoggerDedicated "hidden" logger for request mappings.
 
- 
- 
Constructor Details- 
AbstractHandlerMappingpublic AbstractHandlerMapping()
 
- 
- 
Method Details- 
setDefaultHandlerSet the default handler for this handler mapping. This handler will be returned if no specific mapping was found.Default is null, indicating no default handler.
- 
getDefaultHandlerReturn the default handler for this handler mapping, ornullif none.
- 
setPatternParserEnable use of pre-parsedPathPatterns as an alternative to String pattern matching withAntPathMatcher. The syntax is largely the same but thePathPatternsyntax is more tailored for web applications, and its implementation is more efficient.This property is mutually exclusive with the following others which are effectively ignored when this is set: - setAlwaysUseFullPath(boolean)--- PathPatternsalways use the full path and ignore the servletPath/pathInfo which are decoded and partially normalized and therefore not comparable against the- requestURI.
- setRemoveSemicolonContent(boolean)--- PathPatternsalways ignore semicolon content for path matching purposes, but path parameters remain available for use in controllers via- @MatrixVariable.
- setUrlDecode(boolean)--- PathPatternsmatch one decoded path segment at a time and never need the full decoded path which can cause issues due to decoded reserved characters.
- setUrlPathHelper(org.springframework.web.util.UrlPathHelper)-- the request path is pre-parsed globally by the- DispatcherServletor by- ServletRequestPathFilterusing- ServletRequestPathUtilsand saved in a request attribute for re-use.
- setPathMatcher(org.springframework.util.PathMatcher)-- patterns are parsed to- PathPatternsand used instead of String matching with- PathMatcher.
 By default this is not set. - Parameters:
- patternParser- the parser to use
- Since:
- 5.3
 
- 
getPatternParser- Since:
- 5.3
 
- 
setAlwaysUseFullPathpublic void setAlwaysUseFullPath(boolean alwaysUseFullPath) Shortcut to same property on the configuredUrlPathHelper.Note: This property is mutually exclusive with and ignored when setPatternParser(PathPatternParser)is set.
- 
setUrlDecodepublic void setUrlDecode(boolean urlDecode) Shortcut to same property on the underlyingUrlPathHelper.Note: This property is mutually exclusive with and ignored when setPatternParser(PathPatternParser)is set.- See Also:
 
- 
setRemoveSemicolonContentpublic void setRemoveSemicolonContent(boolean removeSemicolonContent) Shortcut to same property on the underlyingUrlPathHelper.Note: This property is mutually exclusive with and ignored when setPatternParser(PathPatternParser)is set.
- 
setUrlPathHelperConfigure the UrlPathHelper to use for resolution of lookup paths.Note: This property is mutually exclusive with and ignored when setPatternParser(PathPatternParser)is set.
- 
getUrlPathHelperReturn theconfiguredUrlPathHelper.
- 
setPathMatcherConfigure the PathMatcher to use.Note: This property is mutually exclusive with and ignored when setPatternParser(PathPatternParser)is set.By default this is AntPathMatcher.- See Also:
 
- 
getPathMatcherReturn theconfiguredPathMatcher.
- 
setInterceptorsSet the interceptors to apply for all handlers mapped by this handler mapping.Supported interceptor types are HandlerInterceptor,WebRequestInterceptor, andMappedInterceptor. Mapped interceptors apply only to request URLs that match its path patterns. Mapped interceptor beans are also detected by type during initialization.- Parameters:
- interceptors- array of handler interceptors
- See Also:
 
- 
setCorsConfigurationsSet "global" CORS configuration mappings. The first matching URL pattern determines theCorsConfigurationto use which is then furthercombinedwith theCorsConfigurationfor the selected handler.This is mutually exclusive with setCorsConfigurationSource(CorsConfigurationSource).- Since:
- 4.2
- See Also:
 
- 
setCorsConfigurationSourceSet aCorsConfigurationSourcefor "global" CORS config. TheCorsConfigurationdetermined by the source iscombinedwith theCorsConfigurationfor the selected handler.This is mutually exclusive with setCorsConfigurations(Map).- Since:
- 5.1
- See Also:
 
- 
getCorsConfigurationSourceReturn theconfiguredCorsConfigurationSource, if any.- Since:
- 5.3
 
- 
setCorsProcessorConfigure a customCorsProcessorto use to apply the matchedCorsConfigurationfor a request.By default DefaultCorsProcessoris used.- Since:
- 4.2
 
- 
getCorsProcessorReturn the configuredCorsProcessor.
- 
setOrderpublic void setOrder(int order) Specify the order value for this HandlerMapping bean.The default value is Ordered.LOWEST_PRECEDENCE, meaning non-ordered.- See Also:
 
- 
getOrderpublic int getOrder()Description copied from interface:OrderedGet the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet load-on-startupvalues).Same order values will result in arbitrary sort positions for the affected objects. 
- 
setBeanNameDescription copied from interface:BeanNameAwareSet the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
- setBeanNamein interface- BeanNameAware
- Parameters:
- name- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the- BeanFactoryUtils.originalBeanName(String)method to extract the original bean name (without suffix), if desired.
 
- 
formatMappingName
- 
initApplicationContextInitializes the interceptors.- Overrides:
- initApplicationContextin class- ApplicationObjectSupport
- Throws:
- ApplicationContextException- in case of initialization errors
- BeansException- if thrown by ApplicationContext methods
- See Also:
 
- 
extendInterceptorsExtension hook that subclasses can override to register additional interceptors, given the configured interceptors (seesetInterceptors(java.lang.Object...)).Will be invoked before initInterceptors()adapts the specified interceptors intoHandlerInterceptorinstances.The default implementation is empty. - Parameters:
- interceptors- the configured interceptor List (never- null), allowing to add further interceptors before as well as after the existing interceptors
 
- 
detectMappedInterceptorsDetect beans of typeMappedInterceptorand add them to the list of mapped interceptors.This is called in addition to any MappedInterceptors that may have been provided viasetInterceptors(java.lang.Object...), by default adding all beans of typeMappedInterceptorfrom the current context and its ancestors. Subclasses can override and refine this policy.- Parameters:
- mappedInterceptors- an empty list to add to
 
- 
initInterceptorsprotected void initInterceptors()Initialize the specified interceptors adaptingWebRequestInterceptors toHandlerInterceptor.
- 
adaptInterceptorAdapt the given interceptor object toHandlerInterceptor.By default, the supported interceptor types are HandlerInterceptorandWebRequestInterceptor. Each givenWebRequestInterceptoris wrapped withWebRequestHandlerInterceptorAdapter.- Parameters:
- interceptor- the interceptor
- Returns:
- the interceptor downcast or adapted to HandlerInterceptor
- See Also:
 
- 
getAdaptedInterceptorsReturn the adapted interceptors asHandlerInterceptorarray.- Returns:
- the array of HandlerInterceptors, ornullif none
 
- 
getMappedInterceptorsReturn all configuredMappedInterceptors as an array.- Returns:
- the array of MappedInterceptors, ornullif none
 
- 
usesPathPatternspublic boolean usesPathPatterns()- Specified by:
- usesPathPatternsin interface- HandlerMapping
 
- 
getHandler@Nullable public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception Look up a handler for the given request, falling back to the default handler if no specific one is found.- Specified by:
- getHandlerin interface- HandlerMapping
- Parameters:
- request- current HTTP request
- Returns:
- the corresponding handler instance, or the default handler
- Throws:
- Exception- if there is an internal error
- See Also:
 
- 
getHandlerInternalLook up a handler for the given request, returningnullif no specific one is found. This method is called bygetHandler(jakarta.servlet.http.HttpServletRequest); anullreturn value will lead to the default handler, if one is set.On CORS pre-flight requests this method should return a match not for the pre-flight request but for the expected actual request based on the URL path, the HTTP methods from the "Access-Control-Request-Method" header, and the headers from the "Access-Control-Request-Headers" header thus allowing the CORS configuration to be obtained via getCorsConfiguration(Object, HttpServletRequest),Note: This method may also return a pre-built HandlerExecutionChain, combining a handler object with dynamically determined interceptors. Statically specified interceptors will get merged into such an existing chain.- Parameters:
- request- current HTTP request
- Returns:
- the corresponding handler instance, or nullif none found
- Throws:
- Exception- if there is an internal error
 
- 
initLookupPathInitialize the path to use for request mapping.When parsed patterns are enableda parsedRequestPathis expected to have beenparsedexternally by theDispatcherServletorServletRequestPathFilter.Otherwise for String pattern matching via PathMatcherthe path isresolvedby this method.- Since:
- 5.3
 
- 
getHandlerExecutionChainprotected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) Build aHandlerExecutionChainfor the given handler, including applicable interceptors.The default implementation builds a standard HandlerExecutionChainwith the given handler, the common interceptors of the handler mapping, and anyMappedInterceptorsmatching to the current request URL. Interceptors are added in the order they were registered. Subclasses may override this in order to extend/rearrange the list of interceptors.NOTE: The passed-in handler object may be a raw handler or a pre-built HandlerExecutionChain. This method should handle those two cases explicitly, either building a newHandlerExecutionChainor extending the existing chain.For simply adding an interceptor in a custom subclass, consider calling super.getHandlerExecutionChain(handler, request)and invokingHandlerExecutionChain.addInterceptor(org.springframework.web.servlet.HandlerInterceptor)on the returned chain object.- Parameters:
- handler- the resolved handler instance (never- null)
- request- current HTTP request
- Returns:
- the HandlerExecutionChain (never null)
- See Also:
 
- 
hasCorsConfigurationSourceReturntrueif there is aCorsConfigurationSourcefor this handler.- Since:
- 5.2
 
- 
getCorsConfiguration@Nullable protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) Retrieve the CORS configuration for the given handler.- Parameters:
- handler- the handler to check (never- null).
- request- the current request.
- Returns:
- the CORS configuration for the handler, or nullif none
- Since:
- 4.2
 
- 
getCorsHandlerExecutionChainprotected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request, HandlerExecutionChain chain, @Nullable CorsConfiguration config) Update the HandlerExecutionChain for CORS-related handling.For pre-flight requests, the default implementation replaces the selected handler with a simple HttpRequestHandler that invokes the configured setCorsProcessor(org.springframework.web.cors.CorsProcessor).For actual requests, the default implementation inserts a HandlerInterceptor that makes CORS-related checks and adds CORS headers. - Parameters:
- request- the current request
- chain- the handler chain
- config- the applicable CORS configuration (possibly- null)
- Since:
- 4.2
 
 
-