类 AbstractHandlerMethodMapping<T>

java.lang.Object
cn.taketoday.context.support.ApplicationObjectSupport
cn.taketoday.web.handler.AbstractHandlerMapping
cn.taketoday.web.handler.method.AbstractHandlerMethodMapping<T>
类型参数:
T - the mapping for a HandlerMethod containing 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

public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMapping implements cn.taketoday.beans.factory.InitializingBean
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>.

从以下版本开始:
4.0 2022/4/1 22:22
作者:
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen, Harry Yang
  • 字段详细资料

    • SCOPED_TARGET_NAME_PREFIX

      private static final String 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 false for other reasons, while still expecting the bean to be eligible for handler methods.

      Originally defined in ScopedProxyUtils but duplicated here to avoid a hard dependency on the aop module.

      另请参阅:
    • PREFLIGHT_AMBIGUOUS_MATCH

      private static final HandlerMethod PREFLIGHT_AMBIGUOUS_MATCH
    • ALLOW_CORS_CONFIG

      private static final CorsConfiguration ALLOW_CORS_CONFIG
    • detectHandlerMethodsInAncestorContexts

      private boolean detectHandlerMethodsInAncestorContexts
    • namingStrategy

      @Nullable private HandlerMethodMappingNamingStrategy<T> 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 the HandlerInterceptor lookup strategy
      另请参阅:
    • getNamingStrategy

      @Nullable public HandlerMethodMappingNamingStrategy<T> getNamingStrategy()
      Return the configured naming strategy or null.
    • getHandlerMethods

      public Map<T,HandlerMethod> getHandlerMethods()
      Return a (read-only) map with all mappings and HandlerMethod's.
    • getHandlerMethodsForMappingName

      @Nullable public List<HandlerMethod> getHandlerMethodsForMappingName(String mappingName)
      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

      public void registerMapping(T mapping, Object handler, Method method)
      Register the given mapping.

      This method may be invoked at runtime after initialization has completed.

      参数:
      mapping - the mapping for the handler method
      handler - the handler
      method - the method
    • unregisterMapping

      public void unregisterMapping(T mapping)
      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

      protected Set<String> getCandidateBeanNames()
      Determine the names of candidate beans in the application context.
      另请参阅:
    • processCandidateBean

      protected void processCandidateBean(cn.taketoday.beans.factory.BeanFactory beanFactory, String beanName)
      Determine the type of the specified candidate bean and call detectHandlerMethods(java.lang.Object) if identified as a handler type.

      This implementation avoids bean creation through checking BeanFactory.getType(java.lang.String) and calling detectHandlerMethods(java.lang.Object) with the bean name.

      参数:
      beanName - the name of the candidate bean
      另请参阅:
    • detectHandlerMethods

      protected void detectHandlerMethods(Object handler)
      Look for handler methods in the specified handler bean.
      参数:
      handler - either a bean name or an actual handler instance
      另请参阅:
    • detectHandlerMethods

      private void detectHandlerMethods(Class<?> handlerType, Object handler)
      Look for handler methods in the specified handler bean.
      参数:
      handlerType - handler type
      handler - either a bean name or an actual handler instance
      另请参阅:
    • formatMappings

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

      protected void registerHandlerMethod(Object handler, Method method, T mapping)
      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 instance
      method - the method to register
      mapping - the mapping conditions associated with the handler method
      抛出:
      IllegalStateException - if another method was already registered under the same mapping
    • createHandlerMethod

      protected HandlerMethod createHandlerMethod(Object handler, Method method)
      Create the HandlerMethod instance.
      参数:
      handler - either a bean name or an actual handler instance
      method - 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

      protected void handlerMethodsInitialized(Map<T,HandlerMethod> handlerMethods)
      Invoked after all handler methods have been detected.
      参数:
      handlerMethods - a read-only map with handler methods and mappings.
    • getHandlerInternal

      @Nullable protected HandlerMethod getHandlerInternal(RequestContext context)
      Look up a handler method for the given request.
      指定者:
      getHandlerInternal 在类中 AbstractHandlerMapping
      参数:
      context - current HTTP request
      返回:
      the corresponding handler instance, or null if 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 mapping
      request - the current request
      返回:
      the best-matching handler method, or null if 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 metadata
      directLookupPath - mapping lookup path within the current servlet mapping
      request - 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 mappings
      lookupPath - mapping lookup path within the current servlet mapping
      request - the current request
    • hasCorsConfigurationSource

      protected boolean hasCorsConfigurationSource(Object handler)
      从类复制的说明: AbstractHandlerMapping
      Return true if there is a CorsConfigurationSource for this handler.
      覆盖:
      hasCorsConfigurationSource 在类中 AbstractHandlerMapping
    • getCorsConfiguration

      protected CorsConfiguration getCorsConfiguration(Object handler, RequestContext request)
      从类复制的说明: AbstractHandlerMapping
      Retrieve the CORS configuration for the given handler.
      覆盖:
      getCorsConfiguration 在类中 AbstractHandlerMapping
      参数:
      handler - the handler to check (never null).
      request - the current request.
      返回:
      the CORS configuration for the handler, or null if none
    • getHandlerInterceptors

      @Nullable protected HandlerInterceptor[] getHandlerInterceptors(Object handler)
      覆盖:
      getHandlerInterceptors 在类中 AbstractHandlerMapping
    • getInterceptors

      protected List<HandlerInterceptor> getInterceptors(Class<?> controllerClass, Method action)
      Get list of intercepters.
      参数:
      controllerClass - controller class
      action - method
      返回:
      List of HandlerInterceptor objects
    • addInterceptors

      private void addInterceptors(@Nullable cn.taketoday.context.ApplicationContext context, ArrayList<HandlerInterceptor> ret, cn.taketoday.core.annotation.MergedAnnotation<Interceptor> annotation)
    • registerInterceptorBean

      private void registerInterceptorBean(Class<?> interceptor)
    • registry

      private cn.taketoday.beans.factory.support.BeanDefinitionRegistry registry()
    • isHandler

      protected abstract boolean isHandler(Class<?> beanType)
      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

      @Nullable protected abstract T getMappingForMethod(Method method, Class<?> handlerType)
      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 for
      handlerType - the handler type, possibly a sub-type of the method's declaring class
      返回:
      the mapping, or null if the method is not mapped
    • getDirectPaths

      protected abstract Set<String> getDirectPaths(T mapping)
      Return the request mapping paths that are not patterns.
    • getMatchingMapping

      @Nullable protected abstract T getMatchingMapping(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.
      参数:
      mapping - the mapping to get a match for
      request - the current HTTP servlet request
      返回:
      the match, or null if the mapping doesn't match
    • getMappingComparator

      protected abstract Comparator<T> getMappingComparator(RequestContext request)
      Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.
      参数:
      request - the current request
      返回:
      the comparator (never null)