类 AbstractHandlerMethodMapping<T>
- 类型参数:
T- the mapping for aHandlerMethodcontaining the conditions needed to match the handler method to an incoming request.
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.beans.factory.InitializingBean,cn.taketoday.context.ApplicationContextAware,cn.taketoday.context.expression.EmbeddedValueResolverAware,cn.taketoday.core.Ordered,HandlerMapping
- 直接已知子类:
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>.
- 从以下版本开始:
- 4.0 2022/4/1 22:22
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private static class(专用程序包) static final record(专用程序包) final classA registry that maintains all mappings to handler methods, exposing methods to perform lookups and providing concurrent access.protected static final classA 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 -
字段概要
字段修饰符和类型字段说明private static final CorsConfigurationprivate cn.taketoday.context.annotation.AnnotatedBeanDefinitionReaderprivate boolean(专用程序包) final AbstractHandlerMethodMapping<T>.MappingRegistryProvided for testing purposes.private HandlerMethodMappingNamingStrategy<T>private static final HandlerMethodprivate cn.taketoday.beans.factory.support.BeanDefinitionRegistryprivate static final StringBean name prefix for target beans behind scoped proxies.private boolean从类继承的字段 cn.taketoday.web.handler.AbstractHandlerMapping
embeddedValueResolver, mappingsLogger从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.HandlerMapping
HANDLER_MAPPING_BEAN_NAME从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidaddInterceptors(cn.taketoday.context.ApplicationContext context, ArrayList<HandlerInterceptor> ret, cn.taketoday.core.annotation.MergedAnnotation<Interceptor> annotation) private voidaddMatchingMappings(Collection<T> mappings, ArrayList<AbstractHandlerMethodMapping.Match<T>> matches, RequestContext request) voidDetects handler methods at initialization.protected HandlerMethodcreateHandlerMethod(Object handler, Method method) Create the HandlerMethod instance.private voiddetectHandlerMethods(Class<?> handlerType, Object handler) Look for handler methods in the specified handler bean.protected voiddetectHandlerMethods(Object handler) Look for handler methods in the specified handler bean.private StringformatMappings(Class<?> userType, Map<Method, T> methods) Determine the names of candidate beans in the application context.protected CorsConfigurationgetCorsConfiguration(Object handler, RequestContext request) Retrieve the CORS configuration for the given handler.getDirectPaths(T mapping) Return the request mapping paths that are not patterns.protected HandlerInterceptor[]getHandlerInterceptors(Object handler) protected HandlerMethodgetHandlerInternal(RequestContext context) 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 List<HandlerInterceptor>getInterceptors(Class<?> controllerClass, Method action) Get list of intercepters.protected abstract Comparator<T>getMappingComparator(RequestContext request) Return a comparator for sorting matching mappings.protected abstract TgetMappingForMethod(Method method, Class<?> handlerType) Provide the mapping for a handler method.protected abstract TgetMatchingMapping(T mapping, RequestContext 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(AbstractHandlerMethodMapping.Match<T> bestMatch, String directLookupPath, RequestContext request) Invoked when a matching mapping is found.protected HandlerMethodhandleNoMatch(Set<T> mappings, String lookupPath, RequestContext 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 CorsConfigurationinitCorsConfiguration(Object handler, HandlerMethod handlerMethod, 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 HandlerMethodlookupHandlerMethod(String directLookupPath, RequestContext request) Look up the best-matching handler method for the current request.protected voidprocessCandidateBean(cn.taketoday.beans.factory.BeanFactory beanFactory, 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.private voidregisterInterceptorBean(Class<?> interceptor) voidregisterMapping(T mapping, Object handler, Method method) Register the given mapping.private cn.taketoday.beans.factory.support.BeanDefinitionRegistryregistry()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.voidsetUseInheritedInterceptor(boolean useInheritedInterceptor) Configure theHandlerInterceptorlookup strategyvoidunregisterMapping(T mapping) Un-register the given mapping.从类继承的方法 cn.taketoday.web.handler.AbstractHandlerMapping
detectMappedInterceptors, extendInterceptors, formatMappingName, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, getPatternParser, initApplicationContext, resolveEmbeddedVariables, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setEmbeddedValueResolver, setInterceptors, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatch从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
SCOPED_TARGET_NAME_PREFIX
Bean name prefix for target beans behind scoped proxies. Used to exclude those targets from handler method detection, in favor of the corresponding proxies.We're not checking the autowire-candidate status here, which is how the proxy target filtering problem is being handled at the autowiring level, since autowire-candidate may have been turned to
falsefor other reasons, while still expecting the bean to be eligible for handler methods.Originally defined in
ScopedProxyUtilsbut duplicated here to avoid a hard dependency on the aop module.- 另请参阅:
-
PREFLIGHT_AMBIGUOUS_MATCH
-
ALLOW_CORS_CONFIG
-
detectHandlerMethodsInAncestorContexts
private boolean detectHandlerMethodsInAncestorContexts -
namingStrategy
-
registry
@Nullable private cn.taketoday.beans.factory.support.BeanDefinitionRegistry registry -
beanDefinitionReader
@Nullable private cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader beanDefinitionReader -
useInheritedInterceptor
private boolean useInheritedInterceptor -
mappingRegistry
Provided for testing purposes.
-
-
构造器详细资料
-
AbstractHandlerMethodMapping
public AbstractHandlerMethodMapping()
-
-
方法详细资料
-
setDetectHandlerMethodsInAncestorContexts
public 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 root WebApplicationContext) as well.
- 另请参阅:
-
setHandlerMethodMappingNamingStrategy
public 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, e.g. "TC#getFoo" for a class named TestController with method getFoo.
-
setUseInheritedInterceptor
public void setUseInheritedInterceptor(boolean useInheritedInterceptor) Configure theHandlerInterceptorlookup strategy- 另请参阅:
-
BeanDefinitionRegistry.containsBeanDefinition(Class, boolean)addInterceptors(ApplicationContext, ArrayList, MergedAnnotation)
-
getNamingStrategy
Return the configured naming strategy ornull. -
getHandlerMethods
Return a (read-only) map with all mappings and HandlerMethod's. -
getHandlerMethodsForMappingName
Return the handler methods for the given mapping name.- 参数:
mappingName- the mapping name- 返回:
- a list of matching HandlerMethod's or
null; the returned list will never be modified and is safe to iterate. - 另请参阅:
-
registerMapping
Register the given mapping.This method may be invoked at runtime after initialization has completed.
- 参数:
mapping- the mapping for the handler methodhandler- the handlermethod- the method
-
unregisterMapping
Un-register the given mapping.This method may be invoked at runtime after initialization has completed.
- 参数:
mapping- the mapping to unregister
-
afterPropertiesSet
public void afterPropertiesSet()Detects handler methods at initialization.- 指定者:
afterPropertiesSet在接口中cn.taketoday.beans.factory.InitializingBean- 另请参阅:
-
initHandlerMethods
protected void initHandlerMethods()Scan beans in the ApplicationContext, detect and register handler methods. -
getCandidateBeanNames
Determine the names of candidate beans in the application context.- 另请参阅:
-
setDetectHandlerMethodsInAncestorContexts(boolean)BeanFactoryUtils.beanNamesForTypeIncludingAncestors(cn.taketoday.beans.factory.BeanFactory, cn.taketoday.core.ResolvableType)
-
processCandidateBean
protected void processCandidateBean(cn.taketoday.beans.factory.BeanFactory beanFactory, String beanName) Determine 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.- 参数:
beanName- the name of the candidate bean- 另请参阅:
-
detectHandlerMethods
Look for handler methods in the specified handler bean.- 参数:
handler- either a bean name or an actual handler instance- 另请参阅:
-
detectHandlerMethods
Look for handler methods in the specified handler bean.- 参数:
handlerType- handler typehandler- either a bean name or an actual handler instance- 另请参阅:
-
formatMappings
-
registerHandlerMethod
Register a handler method and its unique mapping. Invoked at startup for each detected handler method.- 参数:
handler- the bean name of the handler or the handler instancemethod- the method to registermapping- the mapping conditions associated with the handler method- 抛出:
IllegalStateException- if another method was already registered under the same mapping
-
createHandlerMethod
Create the HandlerMethod instance.- 参数:
handler- either a bean name or an actual handler instancemethod- the target method- 返回:
- the created HandlerMethod
-
initCorsConfiguration
@Nullable protected CorsConfiguration initCorsConfiguration(Object handler, HandlerMethod handlerMethod, Method method, T mapping) Extract and return the CORS configuration for the mapping. -
handlerMethodsInitialized
Invoked after all handler methods have been detected.- 参数:
handlerMethods- a read-only map with handler methods and mappings.
-
getHandlerInternal
Look up a handler method for the given request.- 指定者:
getHandlerInternal在类中AbstractHandlerMapping- 参数:
context- current HTTP request- 返回:
- the corresponding handler instance, or
nullif none found
-
lookupHandlerMethod
@Nullable protected HandlerMethod lookupHandlerMethod(String directLookupPath, RequestContext request) Look up the best-matching handler method for the current request. If multiple matches are found, the best match is selected.- 参数:
directLookupPath- mapping lookup path within the current servlet mappingrequest- the current request- 返回:
- the best-matching handler method, or
nullif no match - 另请参阅:
-
addMatchingMappings
private void addMatchingMappings(Collection<T> mappings, ArrayList<AbstractHandlerMethodMapping.Match<T>> matches, RequestContext request) -
handleMatch
protected void handleMatch(AbstractHandlerMethodMapping.Match<T> bestMatch, String directLookupPath, RequestContext request) Invoked when a matching mapping is found.- 参数:
bestMatch- the best match metadatadirectLookupPath- mapping lookup path within the current servlet mappingrequest- the current request
-
handleNoMatch
@Nullable protected HandlerMethod handleNoMatch(Set<T> mappings, String lookupPath, RequestContext request) Invoked when no matching mapping is not found.- 参数:
mappings- all registered mappingslookupPath- mapping lookup path within the current servlet mappingrequest- the current request
-
hasCorsConfigurationSource
从类复制的说明:AbstractHandlerMappingReturntrueif there is aCorsConfigurationSourcefor this handler. -
getCorsConfiguration
从类复制的说明:AbstractHandlerMappingRetrieve the CORS configuration for the given handler.- 覆盖:
getCorsConfiguration在类中AbstractHandlerMapping- 参数:
handler- the handler to check (nevernull).request- the current request.- 返回:
- the CORS configuration for the handler, or
nullif none
-
getHandlerInterceptors
-
getInterceptors
Get list of intercepters.- 参数:
controllerClass- controller classaction- method- 返回:
- List of
HandlerInterceptorobjects
-
addInterceptors
private void addInterceptors(@Nullable cn.taketoday.context.ApplicationContext context, ArrayList<HandlerInterceptor> ret, cn.taketoday.core.annotation.MergedAnnotation<Interceptor> annotation) -
registerInterceptorBean
-
registry
private cn.taketoday.beans.factory.support.BeanDefinitionRegistry registry() -
isHandler
Whether the given type is a handler with handler methods.- 参数:
beanType- the type of the bean being checked- 返回:
- "true" if this a handler type, "false" otherwise.
-
getMappingForMethod
Provide the mapping for a handler method. A method for which no mapping can be provided is not a handler method.- 参数:
method- the method to provide a mapping forhandlerType- the handler type, possibly a sub-type of the method's declaring class- 返回:
- the mapping, or
nullif the method is not mapped
-
getDirectPaths
Return the request mapping paths that are not patterns. -
getMatchingMapping
Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.- 参数:
mapping- the mapping to get a match forrequest- the current HTTP servlet request- 返回:
- the match, or
nullif the mapping doesn't match
-
getMappingComparator
Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- 参数:
request- the current request- 返回:
- the comparator (never
null)
-