Class AbstractHandlerMethodMapping<T>
- Type Parameters:
- T- the mapping for a- HandlerMethodcontaining the conditions needed to match the handler method to an incoming request.
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- Ordered,- ServletContextAware,- HandlerMapping
- Direct Known Subclasses:
- RequestMappingInfoHandlerMapping
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>.
- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
- 
Field SummaryFields inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingmappingsLoggerFields 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 TypeMethodDescriptionvoidDetects handler methods at initialization.protected HandlerMethodcreateHandlerMethod(Object handler, Method method) Create the HandlerMethod instance.protected voiddetectHandlerMethods(Object handler) Look for handler methods in the specified handler bean.protected String[]Determine the names of candidate beans in the application context.protected @Nullable CorsConfigurationgetCorsConfiguration(Object handler, HttpServletRequest request) Retrieve the CORS configuration for the given handler.getDirectPaths(T mapping) Return the request mapping paths that are not patterns.protected @Nullable HandlerMethodgetHandlerInternal(HttpServletRequest request) Look up a handler method for the given request.Return a (read-only) map with all mappings and HandlerMethod's.getHandlerMethodsForMappingName(String mappingName) Return the handler methods for the given mapping name.protected abstract Comparator<T>getMappingComparator(HttpServletRequest request) Return a comparator for sorting matching mappings.getMappingForMethod(Method method, Class<?> handlerType) Provide the mapping for a handler method.getMatchingMapping(T mapping, HttpServletRequest request) Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.Return the configured naming strategy ornull.protected voidhandleMatch(T mapping, String lookupPath, HttpServletRequest request) Invoked when a matching mapping is found.protected @Nullable HandlerMethodhandleNoMatch(Set<T> mappings, String lookupPath, HttpServletRequest request) Invoked when no matching mapping is not found.protected voidhandlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) Invoked after all handler methods have been detected.protected booleanhasCorsConfigurationSource(Object handler) Returntrueif there is aCorsConfigurationSourcefor this handler.protected @Nullable CorsConfigurationinitCorsConfiguration(Object handler, Method method, T mapping) Extract and return the CORS configuration for the mapping.protected voidScan beans in the ApplicationContext, detect and register handler methods.protected abstract booleanWhether the given type is a handler with handler methods.protected @Nullable HandlerMethodlookupHandlerMethod(String lookupPath, HttpServletRequest request) Look up the best-matching handler method for the current request.protected voidprocessCandidateBean(String beanName) Determine the type of the specified candidate bean and calldetectHandlerMethods(java.lang.Object)if identified as a handler type.protected voidregisterHandlerMethod(Object handler, Method method, T mapping) Register a handler method and its unique mapping.voidregisterMapping(T mapping, Object handler, Method method) Register the given mapping.voidsetDetectHandlerMethodsInAncestorContexts(boolean detectHandlerMethodsInAncestorContexts) Whether to detect handler methods in beans in ancestor ApplicationContexts.voidsetHandlerMethodMappingNamingStrategy(HandlerMethodMappingNamingStrategy<T> namingStrategy) Configure the naming strategy to use for assigning a default name to every mapped handler method.voidsetPatternParser(@Nullable PathPatternParser patternParser) Set thePathPatternParserto parsepatternswith for URL path matching.voidunregisterMapping(T mapping) Un-register the given mapping.Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingadaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, initApplicationContext, initInterceptors, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatternsMethods 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
- 
Constructor Details- 
AbstractHandlerMethodMappingpublic AbstractHandlerMethodMapping()
 
- 
- 
Method Details- 
setPatternParserDescription copied from class:AbstractHandlerMappingSet 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:- AbstractHandlerMapping.setAlwaysUseFullPath(boolean)-- parsed patterns always use the full path and consider the servletPath only when a Servlet is mapped by path prefix.
- AbstractHandlerMapping.setRemoveSemicolonContent(boolean)-- parsed patterns always ignore semicolon content for path matching purposes, but path parameters remain available for use in controllers via- @MatrixVariable.
- AbstractHandlerMapping.setUrlDecode(boolean)-- parsed patterns match one decoded path segment at a time and therefore don't need to decode the full path.
- AbstractHandlerMapping.setUrlPathHelper(org.springframework.web.util.UrlPathHelper)-- for parsed patterns, the request path is parsed once in- DispatcherServletor in- ServletRequestPathFilterusing- ServletRequestPathUtilsand cached in a request attribute.
- AbstractHandlerMapping.setPathMatcher(org.springframework.util.PathMatcher)-- a parsed patterns encapsulates the logic for path matching and does need a- PathMatcher.
 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.- Overrides:
- setPatternParserin class- AbstractHandlerMapping
- Parameters:
- patternParser- the parser to use
 
- 
setDetectHandlerMethodsInAncestorContextspublic void setDetectHandlerMethodsInAncestorContexts(boolean detectHandlerMethodsInAncestorContexts) Whether to detect handler methods in beans in ancestor ApplicationContexts.Default is "false": Only beans in the current ApplicationContext are considered, i.e. only in the context that this HandlerMapping itself is defined in (typically the current DispatcherServlet's context). Switch this flag on to detect handler beans in ancestor contexts (typically the Spring root WebApplicationContext) as well. - See Also:
 
- 
setHandlerMethodMappingNamingStrategypublic void setHandlerMethodMappingNamingStrategy(HandlerMethodMappingNamingStrategy<T> namingStrategy) Configure the naming strategy to use for assigning a default name to every mapped handler method.The default naming strategy is based on the capital letters of the class name followed by "#" and then the method name, for example, "TC#getFoo" for a class named TestController with method getFoo. 
- 
getNamingStrategyReturn the configured naming strategy ornull.
- 
getHandlerMethodsReturn a (read-only) map with all mappings and HandlerMethod's.
- 
getHandlerMethodsForMappingNameReturn the handler methods for the given mapping name.- Parameters:
- mappingName- the mapping name
- Returns:
- a list of matching HandlerMethod's or null; the returned list will never be modified and is safe to iterate.
- See Also:
 
- 
registerMappingRegister the given mapping.This method may be invoked at runtime after initialization has completed. - Parameters:
- mapping- the mapping for the handler method
- handler- the handler
- method- the method
 
- 
unregisterMappingUn-register the given mapping.This method may be invoked at runtime after initialization has completed. - Parameters:
- mapping- the mapping to unregister
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Detects handler methods at initialization.- Specified by:
- afterPropertiesSetin interface- InitializingBean
- See Also:
 
- 
initHandlerMethodsprotected void initHandlerMethods()Scan beans in the ApplicationContext, detect and register handler methods.
- 
getCandidateBeanNamesDetermine the names of candidate beans in the application context.
- 
processCandidateBeanDetermine the type of the specified candidate bean and calldetectHandlerMethods(java.lang.Object)if identified as a handler type.This implementation avoids bean creation through checking BeanFactory.getType(java.lang.String)and callingdetectHandlerMethods(java.lang.Object)with the bean name.- Parameters:
- beanName- the name of the candidate bean
- Since:
- 5.1
- See Also:
 
- 
detectHandlerMethodsLook for handler methods in the specified handler bean.- Parameters:
- handler- either a bean name or an actual handler instance
- See Also:
 
- 
registerHandlerMethodRegister a handler method and its unique mapping. Invoked at startup for each detected handler method.- Parameters:
- handler- the bean name of the handler or the handler instance
- method- the method to register
- mapping- the mapping conditions associated with the handler method
- Throws:
- IllegalStateException- if another method was already registered under the same mapping
 
- 
createHandlerMethodCreate the HandlerMethod instance.- Parameters:
- handler- either a bean name or an actual handler instance
- method- the target method
- Returns:
- the created HandlerMethod
 
- 
initCorsConfigurationprotected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) Extract and return the CORS configuration for the mapping.
- 
handlerMethodsInitializedInvoked after all handler methods have been detected.- Parameters:
- handlerMethods- a read-only map with handler methods and mappings.
 
- 
getHandlerInternalLook up a handler method for the given request.- Specified by:
- getHandlerInternalin class- AbstractHandlerMapping
- Parameters:
- request- current HTTP request
- Returns:
- the corresponding handler instance, or nullif none found
- Throws:
- Exception- if there is an internal error
 
- 
lookupHandlerMethodprotected @Nullable HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception Look up the best-matching handler method for the current request. If multiple matches are found, the best match is selected.- Parameters:
- lookupPath- mapping lookup path within the current servlet mapping
- request- the current request
- Returns:
- the best-matching handler method, or nullif no match
- Throws:
- Exception
- See Also:
 
- 
handleMatchInvoked when a matching mapping is found.- Parameters:
- mapping- the matching mapping
- lookupPath- mapping lookup path within the current servlet mapping
- request- the current request
 
- 
handleNoMatchprotected @Nullable HandlerMethod handleNoMatch(Set<T> mappings, String lookupPath, HttpServletRequest request) throws Exception Invoked when no matching mapping is not found.- Parameters:
- mappings- all registered mappings
- lookupPath- mapping lookup path within the current servlet mapping
- request- the current request
- Throws:
- ServletException- in case of errors
- Exception
 
- 
hasCorsConfigurationSourceDescription copied from class:AbstractHandlerMappingReturntrueif there is aCorsConfigurationSourcefor this handler.- Overrides:
- hasCorsConfigurationSourcein class- AbstractHandlerMapping
 
- 
getCorsConfigurationprotected @Nullable CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) Description copied from class:AbstractHandlerMappingRetrieve the CORS configuration for the given handler.- Overrides:
- getCorsConfigurationin class- AbstractHandlerMapping
- Parameters:
- handler- the handler to check (never- null).
- request- the current request.
- Returns:
- the CORS configuration for the handler, or nullif none
 
- 
isHandlerWhether the given type is a handler with handler methods.- Parameters:
- beanType- the type of the bean being checked
- Returns:
- "true" if this a handler type, "false" otherwise.
 
- 
getMappingForMethodProvide the mapping for a handler method. A method for which no mapping can be provided is not a handler method.- Parameters:
- method- the method to provide a mapping for
- handlerType- the handler type, possibly a subtype of the method's declaring class
- Returns:
- the mapping, or nullif the method is not mapped
 
- 
getDirectPathsReturn the request mapping paths that are not patterns.- Since:
- 5.3
 
- 
getMatchingMappingCheck if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.- Parameters:
- mapping- the mapping to get a match for
- request- the current HTTP servlet request
- Returns:
- the match, or nullif the mapping doesn't match
 
- 
getMappingComparatorReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Parameters:
- request- the current request
- Returns:
- the comparator (never null)
 
 
-