Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.handler

public abstract Class AbstractHandlerMethodMapping<T>

extends AbstractHandlerMapping
implements InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean
Known Direct Subclasses
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
Type Parameters
<T>
the mapping for a HandlerMethod containing the conditions needed to match the handler method to an incoming request.
Imports
java.lang.reflect.Method, java.util.ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.ReentrantReadWriteLock, java.util.function.Function, java.util.stream.Collectors, jakarta.servlet.ServletException, jakarta.servlet.http.HttpServletRequest, org.springframework.aop.support.AopUtils, org.springframework.beans.factory.BeanFactoryUtils, .InitializingBean, org.springframework.core.MethodIntrospector, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .LinkedMultiValueMap, .MultiValueMap, .StringUtils, org.springframework.web.cors.CorsConfiguration, .CorsUtils, org.springframework.web.method.HandlerMethod, org.springframework.web.servlet.HandlerMapping, org.springframework.web.util.pattern.PathPatternParser

Abstract base class for HandlerMapping implementations that define a mapping between a request and a HandlerMethod.

For each registered handler method, a unique mapping is maintained with subclasses defining the details of the mapping type <T>.

Authors
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
Since
3.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class
pack-priv class
AbstractHandlerMethodMapping.MappingRegistry

A registry that maintains all mappings to handler methods, exposing methods to perform lookups and providing concurrent access.

private class
AbstractHandlerMethodMapping.Match

A thin wrapper around a matched HandlerMethod and its mapping, for the purpose of comparing the best match with a comparator in the context of the current request.

private class

Field Summary

Modifier and TypeField and Description
private static final CorsConfiguration
private boolean
private final AbstractHandlerMethodMapping<T>.MappingRegistry
private HandlerMethodMappingNamingStrategy<T>
private static final HandlerMethod
private static final String
SCOPED_TARGET_NAME_PREFIX

Bean name prefix for target beans behind scoped proxies.

Inherited from org.springframework.web.servlet.handler.AbstractHandlerMapping:
mappingsLoggerSUPPRESS_LOGGING_ATTRIBUTE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Detects handler methods at initialization.

protected HandlerMethod

Returns:

the created HandlerMethod
createHandlerMethod
(Object
either a bean name or an actual handler instance
handler
,
Method
the target method
method
)

Create the HandlerMethod instance.

protected void
detectHandlerMethods(Object
either a bean name or an actual handler instance
handler
)

Look for handler methods in the specified handler bean.

private String
formatMappings(Class<?> userType, Map<Method, T> methods)

protected String[]
getCandidateBeanNames()

Determine the names of candidate beans in the application context.

protected CorsConfiguration
getCorsConfiguration(Object
the handler to check (never null).
handler
,
HttpServletRequest
the current request.
request
)

Overrides org.springframework.web.servlet.handler.AbstractHandlerMapping.getCorsConfiguration.

Retrieve the CORS configuration for the given handler.

protected Set<String>
getDirectPaths(T mapping)

Return the request mapping paths that are not patterns.

protected HandlerMethod
getHandlerInternal(HttpServletRequest
current HTTP request
request
)

Implements abstract org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerInternal.

Look up a handler method for the given request.

public Map<T, HandlerMethod>
getHandlerMethods()

Return a (read-only) map with all mappings and HandlerMethod's.

public List<HandlerMethod>

Returns:

a list of matching HandlerMethod's or null; the returned list will never be modified and is safe to iterate.
getHandlerMethodsForMappingName
(String
the mapping name
mappingName
)

Return the handler methods for the given mapping name.

protected abstract Comparator<T>

Returns:

the comparator (never null)
getMappingComparator
(HttpServletRequest
the current request
request
)

Return a comparator for sorting matching mappings.

protected abstract T

Returns:

the mapping, or null if the method is not mapped
getMappingForMethod
(Method
the method to provide a mapping for
method
,
Class<?>
the handler type, possibly a subtype of the method's declaring class
handlerType
)

Provide the mapping for a handler method.

protected Set<String>
getMappingPathPatterns(T mapping)
Deprecated as of 5.3 in favor of providing non-pattern mappings via getDirectPaths(Object) instead

Extract and return the URL paths contained in the supplied mapping.

pack-priv AbstractHandlerMethodMapping<T>.MappingRegistry
getMappingRegistry()

Return the internal mapping registry.

protected abstract T

Returns:

the match, or null if the mapping doesn't match
getMatchingMapping
(T
the mapping to get a match for
mapping
,
HttpServletRequest
the current HTTP servlet request
request
)

Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.

public HandlerMethodMappingNamingStrategy<T>
getNamingStrategy()

Return the configured naming strategy or null.

protected void
handleMatch(T
the matching mapping
mapping
,
String
mapping lookup path within the current servlet mapping
lookupPath
,
HttpServletRequest
the current request
request
)

Invoked when a matching mapping is found.

protected HandlerMethod
handleNoMatch(Set<T>
all registered mappings
mappings
,
String
mapping lookup path within the current servlet mapping
lookupPath
,
HttpServletRequest
the current request
request
)

Invoked when no matching mapping is not found.

protected void
handlerMethodsInitialized(Map<T, HandlerMethod>
a read-only map with handler methods and mappings.
handlerMethods
)

Invoked after all handler methods have been detected.

protected boolean
protected CorsConfiguration
initCorsConfiguration(Object handler, Method method, T mapping)

Extract and return the CORS configuration for the mapping.

protected void
initHandlerMethods()

Scan beans in the ApplicationContext, detect and register handler methods.

protected abstract boolean

Returns:

"true" if this a handler type, "false" otherwise.
isHandler
(Class<?>
the type of the bean being checked
beanType
)

Whether the given type is a handler with handler methods.

protected HandlerMethod

Returns:

the best-matching handler method, or null if no match
lookupHandlerMethod
(String
mapping lookup path within the current servlet mapping
lookupPath
,
HttpServletRequest
the current request
request
)

Look up the best-matching handler method for the current request.

protected void
processCandidateBean(String
the name of the candidate bean
beanName
)

Determine the type of the specified candidate bean and call detectHandlerMethods if identified as a handler type.

protected void
registerHandlerMethod(Object
the bean name of the handler or the handler instance
handler
,
Method
the method to register
method
,
T
the mapping conditions associated with the handler method
mapping
)

Register a handler method and its unique mapping.

public void
registerMapping(T
the mapping for the handler method
mapping
,
Object
the handler
handler
,
Method
the method
method
)

Register the given mapping.

public void
setDetectHandlerMethodsInAncestorContexts(boolean detectHandlerMethodsInAncestorContexts)

Whether to detect handler methods in beans in ancestor ApplicationContexts.

public void
setHandlerMethodMappingNamingStrategy(HandlerMethodMappingNamingStrategy<T> namingStrategy)

Configure the naming strategy to use for assigning a default name to every mapped handler method.

public void
setPatternParser(PathPatternParser
the parser to use
patternParser
)

Overrides org.springframework.web.servlet.handler.AbstractHandlerMapping.setPatternParser.

Set the PathPatternParser to parse patterns with for URL path matching.

public void
unregisterMapping(T
the mapping to unregister
mapping
)

Un-register the given mapping.

Inherited from org.springframework.web.servlet.handler.AbstractHandlerMapping:
adaptInterceptordetectMappedInterceptorsextendInterceptorsformatMappingNamegetAdaptedInterceptorsgetCorsConfigurationSourcegetCorsHandlerExecutionChaingetCorsProcessorgetDefaultHandlergetHandlergetHandlerExecutionChaingetMappedInterceptorsgetOrdergetPathMatchergetPatternParsergetUrlPathHelperinitApplicationContextinitInterceptorsinitLookupPathsetAlwaysUseFullPathsetBeanNamesetCorsConfigurationssetCorsConfigurationSourcesetCorsProcessorsetDefaultHandlersetInterceptorssetOrdersetPathMatchersetRemoveSemicolonContentsetUrlDecodesetUrlPathHelperusesPathPatterns