org.springframework.web.servlet.handler

## Class HandlerMappingIntrospector

- java.lang.Object
- - org.springframework.web.servlet.handler.HandlerMappingIntrospector

- All Implemented Interfaces:
    Aware, InitializingBean, ApplicationContextAware, CorsConfigurationSource

      public class HandlerMappingIntrospector
      extends Object
      implements CorsConfigurationSource, ApplicationContextAware, InitializingBean

  Helper class to get information from the `HandlerMapping` that would serve a specific request.

  Provides the following methods:

  - `getMatchableHandlerMapping(javax.servlet.http.HttpServletRequest)` — obtain a `HandlerMapping` to check request-matching criteria against.
  - `getCorsConfiguration(javax.servlet.http.HttpServletRequest)` — obtain the CORS configuration for the request.

  Note: This is primarily an SPI to allow Spring Security to align its pattern matching with the same pattern matching that would be used in Spring MVC for a given request, in order to avoid security issues. Use of this introspector should be avoided for other purposes because it incurs the overhead of resolving the handler for a request.

  Since:
    4.3.1
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HandlerMappingIntrospector()` Constructor for use with `ApplicationContextAware`.
    `HandlerMappingIntrospector(ApplicationContext context)` Deprecated. as of 4.3.12, in favor of `setApplicationContext(org.springframework.context.ApplicationContext)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Invoked by the containing `BeanFactory` after it has set all bean properties and satisfied `BeanFactoryAware`, `ApplicationContextAware` etc.
    `CorsConfiguration` | `getCorsConfiguration(HttpServletRequest request)` Return a `CorsConfiguration` based on the incoming request.
    `List<HandlerMapping>` | `getHandlerMappings()` Return the configured or detected `HandlerMapping`s.
    `MatchableHandlerMapping` | `getMatchableHandlerMapping(HttpServletRequest request)` Find the `HandlerMapping` that would handle the given request and return a `MatchableHandlerMapping` to use for path matching.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.

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

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

- - ### Constructor Detail

    - #### HandlerMappingIntrospector

          public HandlerMappingIntrospector()

      Constructor for use with `ApplicationContextAware`.

    - #### HandlerMappingIntrospector

          @Deprecated
          public HandlerMappingIntrospector(ApplicationContext context)

      Deprecated. as of 4.3.12, in favor of `setApplicationContext(org.springframework.context.ApplicationContext)`
      Constructor that detects the configured `HandlerMapping`s in the given `ApplicationContext` or falls back on "DispatcherServlet.properties" like the `DispatcherServlet`.

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)

      Description copied from interface: `ApplicationContextAware`
      Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

      Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      Specified by:
        `setApplicationContext` in interface `ApplicationContextAware`
      Parameters:
        `applicationContext` - the ApplicationContext object to be used by this object
      See Also:
        `BeanInitializationException`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Description copied from interface: `InitializingBean`
      Invoked by the containing `BeanFactory` after it has set all bean properties and satisfied `BeanFactoryAware`, `ApplicationContextAware` etc.

      This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`

    - #### getHandlerMappings

          public List<HandlerMapping> getHandlerMappings()

      Return the configured or detected `HandlerMapping`s.

    - #### getMatchableHandlerMapping

          @Nullable
          public MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest request)
                                                                       throws Exception

      Find the `HandlerMapping` that would handle the given request and return a `MatchableHandlerMapping` to use for path matching.
      Parameters:
        `request` - the current request
      Returns:
        the resolved `MatchableHandlerMapping`, or `null`
      Throws:
        `IllegalStateException` - if the matching HandlerMapping is not an instance of `MatchableHandlerMapping`
        `Exception` - if any of the HandlerMapping's raise an exception

    - #### getCorsConfiguration

          @Nullable
          public CorsConfiguration getCorsConfiguration(HttpServletRequest request)

      Description copied from interface: `CorsConfigurationSource`
      Return a `CorsConfiguration` based on the incoming request.
      Specified by:
        `getCorsConfiguration` in interface `CorsConfigurationSource`
      Returns:
        the associated `CorsConfiguration`, or `null` if none