Class AbstractUrlHandlerMapping
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ApplicationContextAware,- Ordered,- HandlerMapping
- Direct Known Subclasses:
- SimpleUrlHandlerMapping
HandlerMapping implementations.
 Supports direct matches, for example, a registered "/test" matches "/test", and
 various path pattern matches, for example, 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 SummaryFields inherited from class org.springframework.web.reactive.handler.AbstractHandlerMappingmappingsLoggerFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.reactive.HandlerMappingBEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionreactor.core.publisher.Mono<Object>getHandlerInternal(ServerWebExchange exchange) Look up a handler for the given request, returning an emptyMonoif no specific one is found.final Map<PathPattern,Object> Return a read-only view of registered path patterns and handlers which may be an actual handler instance or the bean name of lazily initialized handler.protected ObjectlookupHandler(PathContainer lookupPath, ServerWebExchange exchange) Look up a handler instance for the given URL lookup path.protected voidregisterHandler(String[] urlPaths, String beanName) Register the specified handler for the given URL paths.protected voidregisterHandler(String urlPath, Object handler) Register the specified handler for the given URL path.voidsetHandlerPredicate(BiPredicate<Object, ServerWebExchange> handlerPredicate) Configure a predicate for extended matching of the handler that was matched by URL path.voidsetLazyInitHandlers(boolean lazyInitHandlers) Set whether to lazily initialize handlers.protected voidvalidateHandler(Object handler, ServerWebExchange exchange) Validate the given handler against the current request.Methods inherited from class org.springframework.web.reactive.handler.AbstractHandlerMappingformatMappingName, getCorsConfiguration, getCorsProcessor, getHandler, getOrder, getPathPatternParser, hasCorsConfigurationSource, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatchMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Constructor Details- 
AbstractUrlHandlerMappingpublic AbstractUrlHandlerMapping()
 
- 
- 
Method Details- 
setLazyInitHandlerspublic 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. 
- 
getHandlerMapReturn a read-only view of registered path patterns and handlers which may be an actual handler instance or the bean name of lazily initialized handler.
- 
setHandlerPredicateConfigure a predicate for extended matching of the handler that was matched by URL path. This allows for further narrowing of the mapping by checking additional properties of the request. If the predicate returns "false", it result in a no-match, which allows anotherHandlerMappingto match or result in a 404 (NOT_FOUND) response.- Parameters:
- handlerPredicate- a bi-predicate to match the candidate handler against the current exchange.
- Since:
- 5.3.5
- See Also:
 
- 
getHandlerInternalDescription copied from class:AbstractHandlerMappingLook up a handler for the given request, returning an emptyMonoif no specific one is found. This method is called byAbstractHandlerMapping.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:
- getHandlerInternalin class- AbstractHandlerMapping
- Parameters:
- exchange- current exchange
- Returns:
- Monofor the matching handler, if any
 
- 
lookupHandler@Nullable protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception Look up a handler instance for the given URL lookup path.Supports direct matches, for example, a registered "/test" matches "/test", and various path pattern matches, for example, 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 nullif not found
- Throws:
- Exception
- See Also:
 
- 
validateHandlerValidate 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
 
- 
registerHandlerprotected void registerHandler(String[] urlPaths, String beanName) throws 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:
- BeansException- if the handler couldn't be registered
- IllegalStateException- if there is a conflicting handler registered
 
- 
registerHandlerprotected void registerHandler(String urlPath, Object handler) throws 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:
- BeansException- if the handler couldn't be registered
- IllegalStateException- if there is a conflicting handler registered
 
 
-