public interface HandlerMapping
This class can be implemented by application developers, although this is not
necessary, as BeanNameUrlHandlerMapping
and DefaultAnnotationHandlerMapping
are included in the framework. The former is the default if no
HandlerMapping bean is registered in the application context.
HandlerMapping implementations can support mapped interceptors but do not
have to. A handler will always be wrapped in a HandlerExecutionChain
instance, optionally accompanied by some HandlerInterceptor
instances.
The DispatcherServlet will first call each HandlerInterceptor's
preHandle
method in the given order, finally invoking the handler
itself if all preHandle
methods have returned true
.
The ability to parameterize this mapping is a powerful and unusual capability of this MVC framework. For example, it is possible to write a custom mapping based on session state, cookie state or many other variables. No other MVC framework seems to be equally flexible.
Note: Implementations can implement the Ordered
interface to be able to specify a sorting order and thus a priority for getting
applied by DispatcherServlet. Non-Ordered instances get treated as lowest priority.
Ordered
,
AbstractHandlerMapping
,
BeanNameUrlHandlerMapping
,
DefaultAnnotationHandlerMapping
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BEST_MATCHING_PATTERN_ATTRIBUTE
Name of the
HttpServletRequest attribute that contains the
best matching pattern within the handler mapping. |
static java.lang.String |
INTROSPECT_TYPE_LEVEL_MAPPING
Name of the boolean
HttpServletRequest attribute that indicates
whether type-level mappings should be inspected. |
static java.lang.String |
MATRIX_VARIABLES_ATTRIBUTE
Name of the
HttpServletRequest attribute that contains a map with
URI matrix variables. |
static java.lang.String |
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
Name of the
HttpServletRequest attribute that contains the path
within the handler mapping, in case of a pattern match, or the full
relevant URI (typically within the DispatcherServlet's mapping) else. |
static java.lang.String |
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
Name of the
HttpServletRequest attribute that contains the set of
producible MediaTypes applicable to the mapped handler. |
static java.lang.String |
URI_TEMPLATE_VARIABLES_ATTRIBUTE
Name of the
HttpServletRequest attribute that contains the URI
templates map, mapping variable names to values. |
Modifier and Type | Method and Description |
---|---|
HandlerExecutionChain |
getHandler(HttpServletRequest request)
Return a handler and any interceptors for this request.
|
static final java.lang.String PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
HttpServletRequest
attribute that contains the path
within the handler mapping, in case of a pattern match, or the full
relevant URI (typically within the DispatcherServlet's mapping) else.
Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
static final java.lang.String BEST_MATCHING_PATTERN_ATTRIBUTE
HttpServletRequest
attribute that contains the
best matching pattern within the handler mapping.
Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
static final java.lang.String INTROSPECT_TYPE_LEVEL_MAPPING
HttpServletRequest
attribute that indicates
whether type-level mappings should be inspected.
Note: This attribute is not required to be supported by all HandlerMapping implementations.
static final java.lang.String URI_TEMPLATE_VARIABLES_ATTRIBUTE
HttpServletRequest
attribute that contains the URI
templates map, mapping variable names to values.
Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
static final java.lang.String MATRIX_VARIABLES_ATTRIBUTE
HttpServletRequest
attribute that contains a map with
URI matrix variables.
Note: This attribute is not required to be supported by all HandlerMapping implementations and may also not be present depending on whether the HandlerMapping is configured to keep matrix variable content in the request URI.
static final java.lang.String PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
HttpServletRequest
attribute that contains the set of
producible MediaTypes applicable to the mapped handler.
Note: This attribute is not required to be supported by all HandlerMapping implementations. Handlers should not necessarily expect this request attribute to be present in all scenarios.
HandlerExecutionChain getHandler(HttpServletRequest request) throws java.lang.Exception
The returned HandlerExecutionChain contains a handler Object, rather than even a tag interface, so that handlers are not constrained in any way. For example, a HandlerAdapter could be written to allow another framework's handler objects to be used.
Returns null
if no match was found. This is not an error.
The DispatcherServlet will query all registered HandlerMapping beans to find
a match, and only decide there is an error if none can find a handler.
request
- current HTTP requestnull
if no mapping foundjava.lang.Exception
- if there is an internal error