org.springframework.web.reactive.result.method

## Class AbstractHandlerMethodMapping<T>

- java.lang.Object
- - org.springframework.context.support.ApplicationObjectSupport
  - - org.springframework.web.reactive.handler.AbstractHandlerMapping
    - - org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping<T>

Type Parameters:
  `T` - the mapping for a `HandlerMethod` containing the conditions needed to match the handler method to an incoming request.

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

Direct Known Subclasses:
  RequestMappingInfoHandlerMapping

    public abstract class AbstractHandlerMethodMapping<T>
    extends AbstractHandlerMapping
    implements org.springframework.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>`.

Since:
  5.0
Author:
  Rossen Stoyanchev, Brian Clozel, Sam Brannen

### Field Summary

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

`logger`

### Fields inherited from interface org.springframework.web.reactive.HandlerMapping

`BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, 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
`AbstractHandlerMethodMapping()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `afterPropertiesSet()` Detects handler methods at initialization.
`protected org.springframework.web.method.HandlerMethod` `createHandlerMethod(Object handler, Method method)` Create the HandlerMethod instance.
`protected void` `detectHandlerMethods(Object handler)` Look for handler methods in a handler.
`protected org.springframework.web.cors.CorsConfiguration` `getCorsConfiguration(Object handler, org.springframework.web.server.ServerWebExchange exchange)` Retrieve the CORS configuration for the given handler.
`reactor.core.publisher.Mono<org.springframework.web.method.HandlerMethod>` `getHandlerInternal(org.springframework.web.server.ServerWebExchange exchange)` Look up a handler method for the given request.
`Map<T,org.springframework.web.method.HandlerMethod>` `getHandlerMethods()` Return a (read-only) map with all mappings and HandlerMethod's.
`protected abstract Comparator<T>` `getMappingComparator(org.springframework.web.server.ServerWebExchange exchange)` Return a comparator for sorting matching mappings.
`protected abstract T` `getMappingForMethod(Method method, Class<?> handlerType)` Provide the mapping for a handler method.
`protected abstract T` `getMatchingMapping(T mapping, org.springframework.web.server.ServerWebExchange exchange)` Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.
`protected void` `handleMatch(T mapping, org.springframework.web.method.HandlerMethod handlerMethod, org.springframework.web.server.ServerWebExchange exchange)` Invoked when a matching mapping is found.
`protected org.springframework.web.method.HandlerMethod` `handleNoMatch(Set<T> mappings, org.springframework.web.server.ServerWebExchange exchange)` Invoked when no matching mapping is not found.
`protected void` `handlerMethodsInitialized(Map<T,org.springframework.web.method.HandlerMethod> handlerMethods)` Invoked after all handler methods have been detected.
`protected boolean` `hasCorsConfigurationSource(Object handler)` Return `true` if there is a `CorsConfigurationSource` for this handler.
`protected org.springframework.web.cors.CorsConfiguration` `initCorsConfiguration(Object handler, Method method, T mapping)` Extract and return the CORS configuration for the mapping.
`protected void` `initHandlerMethods()` Scan beans in the ApplicationContext, detect and register handler methods.
`protected abstract boolean` `isHandler(Class<?> beanType)` Whether the given type is a handler with handler methods.
`protected org.springframework.web.method.HandlerMethod` `lookupHandlerMethod(org.springframework.web.server.ServerWebExchange exchange)` Look up the best-matching handler method for the current request.
`protected void` `registerHandlerMethod(Object handler, Method method, T mapping)` Register a handler method and its unique mapping.
`void` `registerMapping(T mapping, Object handler, Method method)` Register the given mapping.
`void` `unregisterMapping(T mapping)` Un-register the given mapping.

### Methods inherited from class org.springframework.web.reactive.handler.AbstractHandlerMapping

`formatMappingName, getCorsProcessor, getHandler, getOrder, getPathPatternParser, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatch`

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

`getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext`

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

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

### Constructor Detail

#### AbstractHandlerMethodMapping

    public AbstractHandlerMethodMapping()

### Method Detail

#### getHandlerMethods

    public Map<T,org.springframework.web.method.HandlerMethod> getHandlerMethods()

Return a (read-only) map with all mappings and HandlerMethod's.

#### 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.

Parameters:
  `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.

Parameters:
  `mapping` - the mapping to unregister

#### afterPropertiesSet

    public void afterPropertiesSet()

Detects handler methods at initialization.

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`

#### initHandlerMethods

    protected void initHandlerMethods()

Scan beans in the ApplicationContext, detect and register handler methods.

See Also:
  `isHandler(Class)`, `getMappingForMethod(Method, Class)`, `handlerMethodsInitialized(Map)`

#### detectHandlerMethods

    protected void detectHandlerMethods(Object handler)

Look for handler methods in a handler.

Parameters:
  `handler` - the bean name of a handler or a handler instance

#### 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.

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
Throws:
  `IllegalStateException` - if another method was already registered under the same mapping

#### createHandlerMethod

    protected org.springframework.web.method.HandlerMethod createHandlerMethod(Object handler,
                                                                               Method method)

Create the HandlerMethod instance.

Parameters:
  `handler` - either a bean name or an actual handler instance
  `method` - the target method
Returns:
  the created HandlerMethod

#### initCorsConfiguration

    @Nullable
    protected org.springframework.web.cors.CorsConfiguration initCorsConfiguration(Object handler,
                                                                                             Method method,
                                                                                             T mapping)

Extract and return the CORS configuration for the mapping.

#### handlerMethodsInitialized

    protected void handlerMethodsInitialized(Map<T,org.springframework.web.method.HandlerMethod> handlerMethods)

Invoked after all handler methods have been detected.

Parameters:
  `handlerMethods` - a read-only map with handler methods and mappings.

#### getHandlerInternal

    public reactor.core.publisher.Mono<org.springframework.web.method.HandlerMethod> getHandlerInternal(org.springframework.web.server.ServerWebExchange exchange)

Look up a handler method for the given request.

Specified by:
  `getHandlerInternal` in class `AbstractHandlerMapping`
Parameters:
  `exchange` - the current exchange
Returns:
  `Mono` for the matching handler, if any

#### lookupHandlerMethod

    @Nullable
    protected org.springframework.web.method.HandlerMethod lookupHandlerMethod(org.springframework.web.server.ServerWebExchange exchange)
                                                                                  throws Exception

Look up the best-matching handler method for the current request. If multiple matches are found, the best match is selected.

Parameters:
  `exchange` - the current exchange
Returns:
  the best-matching handler method, or `null` if no match
Throws:
  `Exception`
See Also:
  `handleMatch(T, org.springframework.web.method.HandlerMethod, org.springframework.web.server.ServerWebExchange)`, `handleNoMatch(java.util.Set<T>, org.springframework.web.server.ServerWebExchange)`

#### handleMatch

    protected void handleMatch(T mapping,
                               org.springframework.web.method.HandlerMethod handlerMethod,
                               org.springframework.web.server.ServerWebExchange exchange)

Invoked when a matching mapping is found.

Parameters:
  `mapping` - the matching mapping
  `handlerMethod` - the matching method
  `exchange` - the current exchange

#### handleNoMatch

    @Nullable
    protected org.springframework.web.method.HandlerMethod handleNoMatch(Set<T> mappings,
                                                                                   org.springframework.web.server.ServerWebExchange exchange)
                                                                            throws Exception

Invoked when no matching mapping is not found.

Parameters:
  `mappings` - all registered mappings
  `exchange` - the current exchange
Returns:
  an alternative HandlerMethod or `null`
Throws:
  `Exception` - provides details that can be translated into an error status code

#### hasCorsConfigurationSource

    protected boolean hasCorsConfigurationSource(Object handler)

Description copied from class: `AbstractHandlerMapping`
Return `true` if there is a `CorsConfigurationSource` for this handler.

Overrides:
  `hasCorsConfigurationSource` in class `AbstractHandlerMapping`

#### getCorsConfiguration

    protected org.springframework.web.cors.CorsConfiguration getCorsConfiguration(Object handler,
                                                                                  org.springframework.web.server.ServerWebExchange exchange)

Description copied from class: `AbstractHandlerMapping`
Retrieve the CORS configuration for the given handler.

Overrides:
  `getCorsConfiguration` in class `AbstractHandlerMapping`
Parameters:
  `handler` - the handler to check (never `null`)
  `exchange` - the current exchange
Returns:
  the CORS configuration for the handler, or `null` if none

#### isHandler

    protected abstract boolean isHandler(Class<?> beanType)

Whether the given type is a handler with handler methods.

Parameters:
  `beanType` - the type of the bean being checked
Returns:
  "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.

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 mapping, or `null` if the method is not mapped

#### getMatchingMapping

    @Nullable
    protected abstract T getMatchingMapping(T mapping,
                                                      org.springframework.web.server.ServerWebExchange exchange)

Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.

Parameters:
  `mapping` - the mapping to get a match for
  `exchange` - the current exchange
Returns:
  the match, or `null` if the mapping doesn't match

#### getMappingComparator

    protected abstract Comparator<T> getMappingComparator(org.springframework.web.server.ServerWebExchange exchange)

Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.

Parameters:
  `exchange` - the current exchange
Returns:
  the comparator (never `null`)