org.springframework.web.reactive.handler

## Class AbstractUrlHandlerMapping

- java.lang.Object
- - org.springframework.context.support.ApplicationObjectSupport
  - - org.springframework.web.reactive.handler.AbstractHandlerMapping
    - - org.springframework.web.reactive.handler.AbstractUrlHandlerMapping

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

Direct Known Subclasses:
  SimpleUrlHandlerMapping

    public abstract class AbstractUrlHandlerMapping
    extends AbstractHandlerMapping

Abstract base class for URL-mapped `HandlerMapping` implementations.

Supports direct matches, e.g. a registered "/test" matches "/test", and various path pattern matches, e.g. a registered "/t*" pattern matches both "/test" and "/team", "/test/*" matches all paths under "/test", "/test/**" matches all paths below "/test". For details, see the `PathPattern` javadoc.

Will search all path patterns to find the most specific match for the current request path. The most specific pattern is defined as the longest path pattern with the fewest captured variables and wildcards.

Since:
  5.0
Author:
  Rossen Stoyanchev, Juergen Hoeller, Brian Clozel

### 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
`AbstractUrlHandlerMapping()`

### Method Summary

All Methods Instance Methods Concrete Methods
`reactor.core.publisher.Mono<Object>` `getHandlerInternal(org.springframework.web.server.ServerWebExchange exchange)` Look up a handler for the given request, returning an empty `Mono` if no specific one is found.
`Map<org.springframework.web.util.pattern.PathPattern,Object>` `getHandlerMap()` Return a read-only view of registered path patterns and handlers which may may be an actual handler instance or the bean name of lazily initialized handler.
`protected Object` `lookupHandler(org.springframework.http.server.PathContainer lookupPath, org.springframework.web.server.ServerWebExchange exchange)` Look up a handler instance for the given URL lookup path.
`protected void` `registerHandler(String[] urlPaths, String beanName)` Register the specified handler for the given URL paths.
`protected void` `registerHandler(String urlPath, Object handler)` Register the specified handler for the given URL path.
`void` `setLazyInitHandlers(boolean lazyInitHandlers)` Set whether to lazily initialize handlers.
`protected void` `validateHandler(Object handler, org.springframework.web.server.ServerWebExchange exchange)` Validate the given handler against the current request.

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

`formatMappingName, getCorsConfiguration, getCorsProcessor, getHandler, getOrder, getPathPatternParser, hasCorsConfigurationSource, 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

#### AbstractUrlHandlerMapping

    public AbstractUrlHandlerMapping()

### Method Detail

#### setLazyInitHandlers

    public void setLazyInitHandlers(boolean lazyInitHandlers)

Set whether to lazily initialize handlers. Only applicable to singleton handlers, as prototypes are always lazily initialized. Default is "false", as eager initialization allows for more efficiency through referencing the controller objects directly.

If you want to allow your controllers to be lazily initialized, make them "lazy-init" and set this flag to true. Just making them "lazy-init" will not work, as they are initialized through the references from the handler mapping in this case.

#### getHandlerMap

    public final Map<org.springframework.web.util.pattern.PathPattern,Object> getHandlerMap()

Return a read-only view of registered path patterns and handlers which may may be an actual handler instance or the bean name of lazily initialized handler.

#### getHandlerInternal

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

Description copied from class: `AbstractHandlerMapping`
Look up a handler for the given request, returning an empty `Mono` if no specific one is found. This method is called by `AbstractHandlerMapping.getHandler(org.springframework.web.server.ServerWebExchange)`.

On CORS pre-flight requests this method should return a match not for the pre-flight request but for the expected actual request based on the URL path, the HTTP methods from the "Access-Control-Request-Method" header, and the headers from the "Access-Control-Request-Headers" header.

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

#### lookupHandler

    @Nullable
    protected Object lookupHandler(org.springframework.http.server.PathContainer lookupPath,
                                             org.springframework.web.server.ServerWebExchange exchange)
                                      throws Exception

Look up a handler instance for the given URL lookup path.

Supports direct matches, e.g. a registered "/test" matches "/test", and various path pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the PathPattern class.

Parameters:
  `lookupPath` - the URL the handler is mapped to
  `exchange` - the current exchange
Returns:
  the associated handler instance, or `null` if not found
Throws:
  `Exception`
See Also:
  `PathPattern`

#### validateHandler

    protected void validateHandler(Object handler,
                                   org.springframework.web.server.ServerWebExchange exchange)

Validate the given handler against the current request.

The default implementation is empty. Can be overridden in subclasses, for example to enforce specific preconditions expressed in URL mappings.

Parameters:
  `handler` - the handler object to validate
  `exchange` - current exchange

#### registerHandler

    protected void registerHandler(String[] urlPaths,
                                   String beanName)
                            throws org.springframework.beans.BeansException,
                                   IllegalStateException

Register the specified handler for the given URL paths.

Parameters:
  `urlPaths` - the URLs that the bean should be mapped to
  `beanName` - the name of the handler bean
Throws:
  `org.springframework.beans.BeansException` - if the handler couldn't be registered
  `IllegalStateException` - if there is a conflicting handler registered

#### registerHandler

    protected void registerHandler(String urlPath,
                                   Object handler)
                            throws org.springframework.beans.BeansException,
                                   IllegalStateException

Register the specified handler for the given URL path.

Parameters:
  `urlPath` - the URL the bean should be mapped to
  `handler` - the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
Throws:
  `org.springframework.beans.BeansException` - if the handler couldn't be registered
  `IllegalStateException` - if there is a conflicting handler registered