Class RequestMappingHandlerMapping

All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.EmbeddedValueResolverAware, org.springframework.core.Ordered, HandlerMapping

public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping implements org.springframework.context.EmbeddedValueResolverAware
An extension of RequestMappingInfoHandlerMapping that creates RequestMappingInfo instances from class-level and method-level @RequestMapping annotations.
Since:
5.0
Author:
Rossen Stoyanchev, Sam Brannen
  • Constructor Details

    • RequestMappingHandlerMapping

      public RequestMappingHandlerMapping()
  • Method Details

    • setPathPrefixes

      public void setPathPrefixes(Map<String,Predicate<Class<?>>> prefixes)
      Configure path prefixes to apply to controller methods.

      Prefixes are used to enrich the mappings of every @RequestMapping method whose controller type is matched by a corresponding Predicate in the map. The prefix for the first matching predicate is used, assuming the input map has predictable order.

      Consider using HandlerTypePredicate to group controllers.

      Parameters:
      prefixes - a map with path prefixes as key
      Since:
      5.1
      See Also:
      • HandlerTypePredicate
    • getPathPrefixes

      public Map<String,Predicate<Class<?>>> getPathPrefixes()
      The configured path prefixes as a read-only, possibly empty map.
      Since:
      5.1
    • setContentTypeResolver

      public void setContentTypeResolver(RequestedContentTypeResolver contentTypeResolver)
      Set the RequestedContentTypeResolver to use to determine requested media types. If not set, the default constructor is used.
    • getContentTypeResolver

      public RequestedContentTypeResolver getContentTypeResolver()
      Return the configured RequestedContentTypeResolver.
    • setEmbeddedValueResolver

      public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)
      Specified by:
      setEmbeddedValueResolver in interface org.springframework.context.EmbeddedValueResolverAware
    • afterPropertiesSet

      public void afterPropertiesSet()
      Description copied from class: AbstractHandlerMethodMapping
      Detects handler methods at initialization.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class AbstractHandlerMethodMapping<RequestMappingInfo>
    • isHandler

      protected boolean isHandler(Class<?> beanType)
      Whether the given type is a handler with handler methods. Expects a handler to have a type-level @Controller annotation.
      Specified by:
      isHandler in class AbstractHandlerMethodMapping<RequestMappingInfo>
      Parameters:
      beanType - the type of the bean being checked
      Returns:
      "true" if this a handler type, "false" otherwise.
    • getMappingForMethod

      @Nullable protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType)
      Uses method and type-level @RequestMapping annotations to create the RequestMappingInfo.
      Specified by:
      getMappingForMethod in class AbstractHandlerMethodMapping<RequestMappingInfo>
      Parameters:
      method - the method to provide a mapping for
      handlerType - the handler type, possibly a subtype of the method's declaring class
      Returns:
      the created RequestMappingInfo, or null if the method does not have a @RequestMapping annotation.
      See Also:
    • getCustomTypeCondition

      @Nullable protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType)
      Provide a custom type-level request condition. The custom RequestCondition can be of any type so long as the same condition type is returned from all calls to this method in order to ensure custom request conditions can be combined and compared.

      Consider extending AbstractRequestCondition for custom condition types and using CompositeRequestCondition to provide multiple custom conditions.

      Parameters:
      handlerType - the handler type for which to create the condition
      Returns:
      the condition, or null
    • getCustomMethodCondition

      @Nullable protected RequestCondition<?> getCustomMethodCondition(Method method)
      Provide a custom method-level request condition. The custom RequestCondition can be of any type so long as the same condition type is returned from all calls to this method in order to ensure custom request conditions can be combined and compared.

      Consider extending AbstractRequestCondition for custom condition types and using CompositeRequestCondition to provide multiple custom conditions.

      Parameters:
      method - the handler method for which to create the condition
      Returns:
      the condition, or null
    • createRequestMappingInfo

      protected RequestMappingInfo createRequestMappingInfo(org.springframework.web.bind.annotation.RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition)
      Create a RequestMappingInfo from the supplied @RequestMapping annotation, which is either a directly declared annotation, a meta-annotation, or the synthesized result of merging annotation attributes within an annotation hierarchy.
    • resolveEmbeddedValuesInPatterns

      protected String[] resolveEmbeddedValuesInPatterns(String[] patterns)
      Resolve placeholder values in the given array of patterns.
      Returns:
      a new array with updated patterns
    • registerMapping

      public void registerMapping(RequestMappingInfo mapping, Object handler, Method method)
      Description copied from class: AbstractHandlerMethodMapping
      Register the given mapping.

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

      Overrides:
      registerMapping in class AbstractHandlerMethodMapping<RequestMappingInfo>
      Parameters:
      mapping - the mapping for the handler method
      handler - the handler
      method - the method
    • registerHandlerMethod

      protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping)
      Description copied from class: AbstractHandlerMethodMapping
      Register a handler method and its unique mapping. Invoked at startup for each detected handler method.
      Overrides:
      registerHandlerMethod in class AbstractHandlerMethodMapping<RequestMappingInfo>
      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
    • initCorsConfiguration

      protected org.springframework.web.cors.CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo)
      Description copied from class: AbstractHandlerMethodMapping
      Extract and return the CORS configuration for the mapping.
      Overrides:
      initCorsConfiguration in class AbstractHandlerMethodMapping<RequestMappingInfo>