Top Description Fields Constructors Methods
org.springframework.web.servlet.function.support

public Class RouterFunctionMapping

extends AbstractHandlerMapping
implements InitializingBean, MatchableHandlerMapping
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.handler.MatchableHandlerMapping, org.springframework.web.servlet.HandlerMapping, org.springframework.beans.factory.InitializingBean
Imports
java.util.ArrayList, .Collections, .List, java.util.stream.Collectors, jakarta.servlet.http.HttpServletRequest, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContext, org.springframework.http.converter.ByteArrayHttpMessageConverter, .HttpMessageConverter, .StringHttpMessageConverter, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, org.springframework.web.filter.ServerHttpObservationFilter, org.springframework.web.servlet.function.HandlerFunction, .RouterFunction, .RouterFunctions, .ServerRequest, org.springframework.web.servlet.handler.AbstractHandlerMapping, .MatchableHandlerMapping, .RequestMatchResult, org.springframework.web.util.pattern.PathPattern, .PathPatternParser

HandlerMapping implementation that supports RouterFunctions.

If no RouterFunction is provided at construction time, this mapping will detect all router functions in the application context, and consult them in order.

Authors
Arjen Poutsma, Sebastien Deleuze, Brian Clozel
Since
5.2

Field Summary

Modifier and TypeField and Description
private boolean
private List<HttpMessageConverter<?>>
private RouterFunction<?>
Inherited from org.springframework.web.servlet.handler.AbstractHandlerMapping:
mappingsLogger

Constructor Summary

AccessConstructor and Description
public
RouterFunctionMapping()

Create an empty RouterFunctionMapping.

public
RouterFunctionMapping(RouterFunction<?>
the router function to use for mapping
routerFunction
)

Create a RouterFunctionMapping with the given RouterFunction.

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

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.

protected Object
getHandlerInternal(HttpServletRequest
current HTTP request
servletRequest
)

Implements abstract org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerInternal.

Look up a handler for the given request, returning null if no specific one is found.

public RouterFunction<?>

Returns:

the router function or null
getRouterFunction
()

Return the configured RouterFunction.

private void
initMessageConverters()

Initializes a default set of message converters.

private void
initRouterFunctions()

Detect all router functions in the current application context.

private void
logRouterFunctions(List<RouterFunction<?>> routerFunctions)

public RequestMatchResult
match(HttpServletRequest
the current request
request
,
String
the pattern to match
pattern
)

Implements org.springframework.web.servlet.handler.MatchableHandlerMapping.match.

Determine whether the request matches the given pattern.

private void
setAttributes(HttpServletRequest servletRequest, ServerRequest request, HandlerFunction<?> handlerFunction)

public void
setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFunctionsInAncestorContexts)

Set whether to detect handler functions in ancestor ApplicationContexts.

public void
setMessageConverters(List<HttpMessageConverter<?>> messageConverters)

Set the message body converters to use.

public void
setRouterFunction(RouterFunction<?> routerFunction)

Set the router function to map to.

Inherited from org.springframework.web.servlet.handler.AbstractHandlerMapping:
adaptInterceptordetectMappedInterceptorsextendInterceptorsformatMappingNamegetAdaptedInterceptorsgetCorsConfigurationgetCorsConfigurationSourcegetCorsHandlerExecutionChaingetCorsProcessorgetDefaultHandlergetHandlergetHandlerExecutionChaingetMappedInterceptorsgetOrdergetPathMatchergetPatternParsergetUrlPathHelperhasCorsConfigurationSourceinitApplicationContextinitInterceptorsinitLookupPathsetAlwaysUseFullPathsetBeanNamesetCorsConfigurationssetCorsConfigurationSourcesetCorsProcessorsetDefaultHandlersetInterceptorssetOrdersetPathMatchersetPatternParsersetRemoveSemicolonContentsetUrlDecodesetUrlPathHelperusesPathPatterns

Field Detail

detectHandlerFunctionsInAncestorContextsback to summary
private boolean detectHandlerFunctionsInAncestorContexts
messageConvertersback to summary
private List<HttpMessageConverter<?>> messageConverters
routerFunctionback to summary
private RouterFunction<?> routerFunction
Annotations
@Nullable

Constructor Detail

RouterFunctionMappingback to summary
public RouterFunctionMapping()

Create an empty RouterFunctionMapping.

If this constructor is used, this mapping will detect all RouterFunction instances available in the application context.

RouterFunctionMappingback to summary
public RouterFunctionMapping(RouterFunction<?> routerFunction)

Create a RouterFunctionMapping with the given RouterFunction.

If this constructor is used, no application context detection will occur.

Parameters
routerFunction:RouterFunction<?>

the router function to use for mapping

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws Exception

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

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.

Annotations
@Override
Exceptions
Exception:
in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
getHandlerInternalback to summary
protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception

Implements abstract org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerInternal.

Doc from org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerInternal.

Look up a handler for the given request, returning null if no specific one is found. This method is called by getHandler; a null return value will lead to the default handler, if one is set.

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 thus allowing the CORS configuration to be obtained via getCorsConfiguration(Object, HttpServletRequest),

Note

This method may also return a pre-built HandlerExecutionChain, combining a handler object with dynamically determined interceptors. Statically specified interceptors will get merged into such an existing chain.

Parameters
servletRequest:HttpServletRequest

current HTTP request

Returns:Object

the corresponding handler instance, or null if none found

Annotations
@Override
@Nullable
Exceptions
Exception:
if there is an internal error
getRouterFunctionback to summary
public RouterFunction<?> getRouterFunction()

Return the configured RouterFunction.

Note

When router functions are detected from the ApplicationContext, this method may return null if invoked prior to afterPropertiesSet().

Returns:RouterFunction<?>

the router function or null

Annotations
@Nullable
initMessageConvertersback to summary
private void initMessageConverters()

Initializes a default set of message converters.

initRouterFunctionsback to summary
private void initRouterFunctions()

Detect all router functions in the current application context.

logRouterFunctionsback to summary
private void logRouterFunctions(List<RouterFunction<?>> routerFunctions)
matchback to summary
public RequestMatchResult match(HttpServletRequest request, String pattern)

Implements org.springframework.web.servlet.handler.MatchableHandlerMapping.match.

Doc from org.springframework.web.servlet.handler.MatchableHandlerMapping.match.

Determine whether the request matches the given pattern. Use this method when getPatternParser() returns null which means that the HandlerMapping is using String pattern matching.

Parameters
request:HttpServletRequest

the current request

pattern:String

the pattern to match

Returns:RequestMatchResult

the result from request matching, or null if none

Annotations
@Nullable
@Override
setAttributesback to summary
private void setAttributes(HttpServletRequest servletRequest, ServerRequest request, HandlerFunction<?> handlerFunction)
setDetectHandlerFunctionsInAncestorContextsback to summary
public void setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFunctionsInAncestorContexts)

Set whether to detect handler functions in ancestor ApplicationContexts.

Default is "false": Only handler functions in the current ApplicationContext will be detected, i.e. only in the context that this HandlerMapping itself is defined in (typically the current DispatcherServlet's context).

Switch this flag on to detect handler beans in ancestor contexts (typically the Spring root WebApplicationContext) as well.

setMessageConvertersback to summary
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)

Set the message body converters to use.

These converters are used to convert from and to HTTP requests and responses.

setRouterFunctionback to summary
public void setRouterFunction(RouterFunction<?> routerFunction)

Set the router function to map to.

If this property is used, no application context detection will occur.