Class AbstractHandlerMapping
- All Implemented Interfaces:
Aware, BeanNameAware, ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping
- Direct Known Subclasses:
AbstractHandlerMethodMapping, AbstractUrlHandlerMapping, RouterFunctionMapping
HandlerMapping
implementations. Supports ordering, a default handler, and 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 Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogDedicated "hidden" logger for request mappings.Fields inherited from class ApplicationObjectSupport
loggerFields inherited from interface HandlerMapping
API_VERSION_ATTRIBUTE, BEST_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 Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier 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(Object...)).protected Stringfinal HandlerInterceptor @Nullable []Return all configured interceptors adapted toHandlerInterceptor.Return the configuredApiVersionStrategystrategy.protected @Nullable CorsConfigurationgetCorsConfiguration(Object handler, jakarta.servlet.http.HttpServletRequest request) Retrieve the CORS configuration for the given handler.Return theconfiguredCorsConfigurationSource, if any.protected HandlerExecutionChaingetCorsHandlerExecutionChain(jakarta.servlet.http.HttpServletRequest request, HandlerExecutionChain chain, @Nullable CorsConfiguration config) UpdateHandlerExecutionChainfor CORS requests, inserting an interceptor at the start of the chain to perform CORS checks, and also using a no-op handler for preflight requests.Return the configuredCorsProcessor.Return the default handler for this handler mapping, ornullif none.getHandler(jakarta.servlet.http.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, jakarta.servlet.http.HttpServletRequest request) Build aHandlerExecutionChainfor the given handler, including applicable interceptors.getHandlerInternal(jakarta.servlet.http.HttpServletRequest request) Look up a handler for the given request, returningnullif no specific one is found.protected final MappedInterceptor @Nullable []Return all configuredMappedInterceptors as an array.intgetOrder()Get the order value of this object.Deprecated, for removal: This API element is subject to removal in a future version.Return theconfiguredPathPatternParser, ornullotherwise which indicates that String pattern matching withAntPathMatcheris enabled instead.Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.protected booleanhasCorsConfigurationSource(Object handler) Returntrueif there is aCorsConfigurationSourcefor this handler.protected voidInitializes the interceptors.protected voidInitialize the specified interceptors adaptingWebRequestInterceptors toHandlerInterceptor.protected StringinitLookupPath(jakarta.servlet.http.HttpServletRequest request) Initialize the path to use for request mapping.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath) Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)voidsetApiVersionStrategy(@Nullable ApiVersionStrategy strategy) Configure a strategy to manage API versioning.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(@Nullable 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) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.voidsetPatternParser(@Nullable PathPatternParser patternParser) Set thePathPatternParserto parsepatternswith for URL path matching.voidsetRemoveSemicolonContent(boolean removeSemicolonContent) Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)voidsetUrlDecode(boolean urlDecode) Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)voidsetUrlPathHelper(UrlPathHelper urlPathHelper) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.booleanMethods inherited from class WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Field Details
-
mappingsLogger
protected final org.apache.commons.logging.Log mappingsLoggerDedicated "hidden" logger for request mappings.
-
-
Constructor Details
-
AbstractHandlerMapping
public AbstractHandlerMapping()
-
-
Method Details
-
setDefaultHandler
-
getDefaultHandler
-
setPatternParser
Set thePathPatternParserto parsepatternswith for URL path matching. Parsed patterns provide a more modern and efficient alternative to String path matching viaAntPathMatcher.Note: This property is mutually exclusive with the below properties, all of which are not necessary for parsed patterns and are ignored when a
PathPatternParseris available:setAlwaysUseFullPath(boolean)-- parsed patterns always use the full path and consider the servletPath only when a Servlet is mapped by path prefix.setRemoveSemicolonContent(boolean)-- parsed patterns always ignore semicolon content for path matching purposes, but path parameters remain available for use in controllers via@MatrixVariable.setUrlDecode(boolean)-- parsed patterns match one decoded path segment at a time and therefore don't need to decode the full path.setUrlPathHelper(UrlPathHelper)-- for parsed patterns, the request path is parsed once inDispatcherServletor inServletRequestPathFilterusingServletRequestPathUtilsand cached in a request attribute.setPathMatcher(PathMatcher)-- a parsed patterns encapsulates the logic for path matching and does need aPathMatcher.
By default, as of 6.0, this is set to a
PathPatternParserinstance with default settings and therefore use of parsed patterns is enabled. Set this tonullto switch to String path matching viaAntPathMatcherinstead.- Parameters:
patternParser- the parser to use- Since:
- 5.3
-
getPatternParser
Return theconfiguredPathPatternParser, ornullotherwise which indicates that String pattern matching withAntPathMatcheris enabled instead.- Since:
- 5.3
-
setAlwaysUseFullPath
Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)Shortcut to same property on the configuredUrlPathHelper.Note: This property is mutually exclusive with and ignored when
setPatternParser(PathPatternParser)is set.- See Also:
-
setUrlDecode
Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)Shortcut to same property on the underlyingUrlPathHelper.Note: This property is mutually exclusive with and ignored when
setPatternParser(PathPatternParser)is set.- See Also:
-
setRemoveSemicolonContent
Deprecated.as of 6.0, in favor of usingsetUrlPathHelper(UrlPathHelper)Shortcut to same property on the underlyingUrlPathHelper.Note: This property is mutually exclusive with and ignored when
setPatternParser(PathPatternParser)is set.- See Also:
-
setUrlPathHelper
Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Configure the UrlPathHelper to use for resolution of lookup paths.Note: This property is mutually exclusive with and ignored when
setPatternParser(PathPatternParser)is set. -
getUrlPathHelper
Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherand
-
PathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.