public class RouterFunctionMapping extends AbstractHandlerMapping implements org.springframework.beans.factory.InitializingBean
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.
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
Constructor and Description |
---|
RouterFunctionMapping()
Create an empty
RouterFunctionMapping . |
RouterFunctionMapping(RouterFunction<?> routerFunction)
Create a
RouterFunctionMapping with the given RouterFunction . |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected Object |
getHandlerInternal(HttpServletRequest servletRequest)
Look up a handler for the given request, returning
null if no
specific one is found. |
RouterFunction<?> |
getRouterFunction()
Return the configured
RouterFunction . |
void |
setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFunctionsInAncestorContexts)
Set whether to detect handler functions in ancestor ApplicationContexts.
|
void |
setMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters) |
void |
setRouterFunction(RouterFunction<?> routerFunction)
Set the router function to map to.
|
adaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfiguration, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, hasCorsConfigurationSource, initApplicationContext, initInterceptors, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setPatternParser, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatterns
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
public RouterFunctionMapping()
RouterFunctionMapping
.
If this constructor is used, this mapping will detect all
RouterFunction
instances available in the application context.
public RouterFunctionMapping(RouterFunction<?> routerFunction)
RouterFunctionMapping
with the given RouterFunction
.
If this constructor is used, no application context detection will occur.
routerFunction
- the router function to use for mappingpublic void setRouterFunction(@Nullable RouterFunction<?> routerFunction)
If this property is used, no application context detection will occur.
@Nullable public RouterFunction<?> getRouterFunction()
RouterFunction
.
Note: When router functions are detected from the
ApplicationContext, this method may return null
if invoked
prior to afterPropertiesSet()
.
null
public void setMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
public void setDetectHandlerFunctionsInAncestorContexts(boolean detectHandlerFunctionsInAncestorContexts)
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.
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
@Nullable protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception
AbstractHandlerMapping
null
if no
specific one is found. This method is called by AbstractHandlerMapping.getHandler(javax.servlet.http.HttpServletRequest)
;
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 AbstractHandlerMapping.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.
getHandlerInternal
in class AbstractHandlerMapping
servletRequest
- current HTTP requestnull
if none foundException
- if there is an internal error