org.springframework.web.servlet.mvc.method.annotation

## Class RequestMappingHandlerMapping

- java.lang.Object
- - org.springframework.context.support.ApplicationObjectSupport
  - - org.springframework.web.context.support.WebApplicationObjectSupport
    - - org.springframework.web.servlet.handler.AbstractHandlerMapping
      - - org.springframework.web.servlet.handler.AbstractHandlerMethodMapping<RequestMappingInfo>
        - - org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
          - - org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

- All Implemented Interfaces:
    Aware, InitializingBean, ApplicationContextAware, EmbeddedValueResolverAware, Ordered, ServletContextAware, HandlerMapping

      public class RequestMappingHandlerMapping
      extends RequestMappingInfoHandlerMapping
      implements EmbeddedValueResolverAware

  Creates `RequestMappingInfo` instances from type and method-level `@RequestMapping` annotations in `@Controller` classes.
  Since:
    3.1
  Author:
    Arjen Poutsma, Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

      `logger`

    - ### Fields inherited from interface org.springframework.web.servlet.HandlerMapping

      `BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE`

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RequestMappingHandlerMapping()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Detects handler methods at initialization.
    `protected RequestMappingInfo` | `createRequestMappingInfo(RequestMapping annotation, RequestCondition<?> customCondition)` Created a RequestMappingInfo from a RequestMapping annotation.
    `ContentNegotiationManager` | `getContentNegotiationManager()` Return the configured `ContentNegotiationManager`.
    `protected RequestCondition<?>` | `getCustomMethodCondition(Method method)` Provide a custom method-level request condition.
    `protected RequestCondition<?>` | `getCustomTypeCondition(Class<?> handlerType)` Provide a custom type-level request condition.
    `List<String>` | `getFileExtensions()` Return the file extensions to use for suffix pattern matching.
    `protected RequestMappingInfo` | `getMappingForMethod(Method method, Class<?> handlerType)` Uses method and type-level @`RequestMapping` annotations to create the RequestMappingInfo.
    `protected boolean` | `isHandler(Class<?> beanType)` Whether the given type is a handler with handler methods.
    `protected String[]` | `resolveEmbeddedValuesInPatterns(String[] patterns)` Resolve placeholder values in the given array of patterns.
    `void` | `setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)` Set the `ContentNegotiationManager` to use to determine requested media types.
    `void` | `setEmbeddedValueResolver(StringValueResolver resolver)` Set the StringValueResolver to use for resolving embedded definition values.
    `void` | `setUseRegisteredSuffixPatternMatch(boolean useRegsiteredSuffixPatternMatch)` Whether to use suffix pattern match for registered file extensions only when matching patterns to requests.
    `void` | `setUseSuffixPatternMatch(boolean useSuffixPatternMatch)` Whether to use suffix pattern match (".*") when matching patterns to requests.
    `void` | `setUseTrailingSlashMatch(boolean useTrailingSlashMatch)` Whether to match to URLs irrespective of the presence of a trailing slash.
    `boolean` | `useRegisteredSuffixPatternMatch()` Whether to use registered suffixes for pattern matching.
    `boolean` | `useSuffixPatternMatch()` Whether to use suffix pattern matching.
    `boolean` | `useTrailingSlashMatch()` Whether to match to URLs irrespective of the presence of a trailing slash.

    - ### Methods inherited from class org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping

      `getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatch`

    - ### Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMethodMapping

      `createHandlerMethod, detectHandlerMethods, getHandlerInternal, getHandlerMethods, handlerMethodsInitialized, initHandlerMethods, lookupHandlerMethod, registerHandlerMethod, setDetectHandlerMethodsInAncestorContexts`

    - ### Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping

      `adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initApplicationContext, initInterceptors, setAlwaysUseFullPath, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper`

    - ### Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

      `getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext`

    - ### Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

      `getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RequestMappingHandlerMapping

          public RequestMappingHandlerMapping()

  - ### Method Detail

    - #### setUseSuffixPatternMatch

          public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch)

      Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*".

      The default value is `true`.

      Also see `setUseRegisteredSuffixPatternMatch(boolean)` for more fine-grained control over specific suffixes to allow.

    - #### setUseRegisteredSuffixPatternMatch

          public void setUseRegisteredSuffixPatternMatch(boolean useRegsiteredSuffixPatternMatch)

      Whether to use suffix pattern match for registered file extensions only when matching patterns to requests.

      If enabled, a controller method mapped to "/users" also matches to "/users.json" assuming ".json" is a file extension registered with the provided `contentNegotiationManager`. This can be useful for allowing only specific URL extensions to be used as well as in cases where a "." in the URL path can lead to ambiguous interpretation of path variable content, (e.g. given "/users/{user}" and incoming URLs such as "/users/john.j.joe" and "/users/john.j.joe.json").

      If enabled, this flag also enables `useSuffixPatternMatch`. The default value is `false`.

    - #### setUseTrailingSlashMatch

          public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)

      Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to "/users" also matches to "/users/".

      The default value is `true`.

    - #### setEmbeddedValueResolver

          public void setEmbeddedValueResolver(StringValueResolver resolver)

      Description copied from interface: `EmbeddedValueResolverAware`
      Set the StringValueResolver to use for resolving embedded definition values.
      Specified by:
        `setEmbeddedValueResolver` in interface `EmbeddedValueResolverAware`

    - #### setContentNegotiationManager

          public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)

      Set the `ContentNegotiationManager` to use to determine requested media types. If not set, the default constructor is used.

    - #### useSuffixPatternMatch

          public boolean useSuffixPatternMatch()

      Whether to use suffix pattern matching.

    - #### useRegisteredSuffixPatternMatch

          public boolean useRegisteredSuffixPatternMatch()

      Whether to use registered suffixes for pattern matching.

    - #### useTrailingSlashMatch

          public boolean useTrailingSlashMatch()

      Whether to match to URLs irrespective of the presence of a trailing slash.

    - #### getContentNegotiationManager

          public ContentNegotiationManager getContentNegotiationManager()

      Return the configured `ContentNegotiationManager`.

    - #### getFileExtensions

          public List<String> getFileExtensions()

      Return the file extensions to use for suffix pattern matching.

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Description copied from class: `AbstractHandlerMethodMapping`
      Detects handler methods at initialization.
      Specified by:
        `afterPropertiesSet` in interface `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

          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 sub-type of the method's declaring class
      Returns:
        the created RequestMappingInfo, or `null` if the method does not have a `@RequestMapping` annotation.
      See Also:
        `getCustomMethodCondition(Method)`, `getCustomTypeCondition(Class)`

    - #### getCustomTypeCondition

          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

          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(RequestMapping annotation,
                                                    RequestCondition<?> customCondition)

      Created a RequestMappingInfo from a RequestMapping annotation.

    - #### resolveEmbeddedValuesInPatterns

          protected String[] resolveEmbeddedValuesInPatterns(String[] patterns)

      Resolve placeholder values in the given array of patterns.
      Returns:
        a new array with updated patterns