HandlerMapping implementations.
Supports literal matches and pattern matches such as "/test/*", "/test/**",
and others. For details on pattern syntax refer to PathPattern when
parsed patterns are enabled or see
AntPathMatcher otherwise. The syntax is largely the same but the
PathPattern syntax is more tailored for web applications, and its
implementation is more efficient.
All path patterns are checked in order to find the most exact match for the current request path where the "most exact" is the longest path pattern that matches the current request path.
| Modifier and Type | Class and Description |
|---|---|
| private class | AbstractUrlHandlerMapping.
Special interceptor for exposing the
|
| private class | AbstractUrlHandlerMapping.
Special interceptor for exposing the
|
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private boolean | |
| private final Map | |
| private Object | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | Returns: the final handler objectthe raw handler to expose rawHandler, String bestMatchingPattern, String the path to expose before executing the handler pathWithinMapping, Map<String, String> the URI template variables, can be uriTemplateVariables)null if no variables foundBuild a handler object for the given raw handler, exposing the actual
handler, the |
| protected void | exposePathWithinMapping(String bestMatchingPattern, String
the path within the current mapping pathWithinMapping, HttpServletRequest the request to expose the path to request)Expose the path within the current mapping as request attribute. |
| protected void | exposeUriTemplateVariables(Map<String, String>
the URI template variables uriTemplateVariables, HttpServletRequest the request to expose the path to request)Expose the URI templates variables as request attribute. |
| private Object | |
| private String | |
| protected Object | Returns: the handler instance, ornull if none foundcurrent HTTP request request)Implements abstract org. Look up a handler for the URL path of the given request. |
| public final Map | getHandlerMap()
Return the handler mappings as a read-only Map, with the registered path or pattern as key and the handler object (or handler bean name in case of a lazy-init handler), as value. |
| public final Map | getPathPatternHandlerMap()
Identical to |
| public Object | getRootHandler()
Return the root handler for this handler mapping (registered for "/"),
or |
| protected Object | Returns: a matching handler, ornull if not foundthe parsed RequestPath path, String the String lookupPath for checking direct hits lookupPath, HttpServletRequest current HTTP request request)Look up a handler instance for the given URL path. |
| protected Object | Returns: a matching handler, ornull if not foundthe path to match patterns against lookupPath, HttpServletRequest current HTTP request request)Look up a handler instance for the given URL path. |
| public RequestMatchResult | match(HttpServletRequest
the current request request, String the pattern to match pattern)Implements org. Determine whether the request matches the given pattern. |
| protected void | registerHandler(String[]
the URLs that the bean should be mapped to urlPaths, String the name of the handler bean beanName)Register the specified handler for the given URL paths. |
| protected void | registerHandler(String
the URL the bean should be mapped to urlPath, Object the handler instance or handler bean name String
(a bean name will automatically be resolved into the corresponding handler bean) handler)Register the specified handler for the given URL path. |
| public void | |
| public void | setPatternParser(PathPatternParser
the parser to use patternParser)Overrides org. Set the |
| public void | setRootHandler(Object rootHandler)
Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/"). |
| public void | setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Deprecated
since 6.0. as of 6.0, see
PathPatternParser#setMatchOptionalTrailingSeparator(boolean)
Whether to match to URLs irrespective of the presence of a trailing slash. |
| protected boolean | |
| public boolean | |
| protected void | validateHandler(Object
the handler object to validate handler, HttpServletRequest current HTTP request request)Validate the given handler against the current request. |
| handlerMap | back to summary |
|---|---|
| private final Map<String, Object> handlerMap | |
| lazyInitHandlers | back to summary |
|---|---|
| private boolean lazyInitHandlers | |
| pathPatternHandlerMap | back to summary |
|---|---|
| private final Map<PathPattern, Object> pathPatternHandlerMap | |
| rootHandler | back to summary |
|---|---|
| private Object rootHandler
| |
| useTrailingSlashMatch | back to summary |
|---|---|
| private boolean useTrailingSlashMatch | |
| AbstractUrlHandlerMapping | back to summary |
|---|---|
| public AbstractUrlHandlerMapping() | |
| buildPathExposingHandler | back to summary |
|---|---|
| protected Object buildPathExposingHandler(Object rawHandler, String bestMatchingPattern, String pathWithinMapping, Map<String, String> uriTemplateVariables) Build a handler object for the given raw handler, exposing the actual
handler, the The default implementation builds a | |
| exposePathWithinMapping | back to summary |
|---|---|
| protected void exposePathWithinMapping(String bestMatchingPattern, String pathWithinMapping, HttpServletRequest request) Expose the path within the current mapping as request attribute.
| |
| exposeUriTemplateVariables | back to summary |
|---|---|
| protected void exposeUriTemplateVariables(Map<String, String> uriTemplateVariables, HttpServletRequest request) Expose the URI templates variables as request attribute.
| |
| getDirectMatch | back to summary |
|---|---|
private Object getDirectMatch(String urlPath, HttpServletRequest request) throws Exception
| |
| getHandlerDescription | back to summary |
|---|---|
| private String getHandlerDescription(Object handler) | |
| getHandlerInternal | back to summary |
|---|---|
| protected Object getHandlerInternal(HttpServletRequest request) throws Exception Implements abstract org. Look up a handler for the URL path of the given request.
| |
| getHandlerMap | back to summary |
|---|---|
| public final Map Return the handler mappings as a read-only Map, with the registered path or pattern as key and the handler object (or handler bean name in case of a lazy-init handler), as value.
| |
| getPathPatternHandlerMap | back to summary |
|---|---|
| public final Map Identical to
| |
| getRootHandler | back to summary |
|---|---|
| public Object getRootHandler() Return the root handler for this handler mapping (registered for "/"),
or
| |
| lookupHandler | back to summary |
|---|---|
| protected Object lookupHandler(RequestPath path, String lookupPath, HttpServletRequest request) throws Exception Look up a handler instance for the given URL path. This method is used
when parsed
| |
| lookupHandler | back to summary |
|---|---|
| protected Object lookupHandler(String lookupPath, HttpServletRequest request) throws Exception Look up a handler instance for the given URL path. This method is used
when String pattern matching with
| |
| match | back to summary |
|---|---|
| public RequestMatchResult match(HttpServletRequest request, String pattern) Implements org. Doc from org. Determine whether the request matches the given pattern. Use this method
when
| |
| registerHandler | back to summary |
|---|---|
| protected void registerHandler(String[] urlPaths, String beanName) throws BeansException, IllegalStateException Register the specified handler for the given URL paths.
| |
| registerHandler | back to summary |
|---|---|
| protected void registerHandler(String urlPath, Object handler) throws BeansException, IllegalStateException Register the specified handler for the given URL path.
| |
| setLazyInitHandlers | back to summary |
|---|---|
| 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. | |
| setPatternParser | back to summary |
|---|---|
| public void setPatternParser(PathPatternParser patternParser) Overrides org. Doc from org. Set the Note: This property is mutually exclusive with the
below properties, all of which are not necessary for parsed patterns and
are ignored when a
By default, as of 6.0, this is set to a
| |
| setRootHandler | back to summary |
|---|---|
| public void setRootHandler(Object rootHandler) Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/"). Default is | |
| setUseTrailingSlashMatch | back to summary |
|---|---|
| public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a URL pattern such as "/users" also matches to "/users/". The default value is
| |
| supportsTypeLevelMappings | back to summary |
|---|---|
| protected boolean supportsTypeLevelMappings() Indicates whether this handler mapping support type-level mappings. Default to | |
| useTrailingSlashMatch | back to summary |
|---|---|
| public boolean useTrailingSlashMatch() Whether to match to URLs irrespective of the presence of a trailing slash. | |
| validateHandler | back to summary |
|---|---|
| protected void validateHandler(Object handler, HttpServletRequest request) throws Exception 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.
| |
AbstractUrlHandlerMapping#PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE attribute.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | preHandle(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object chosen handler to execute, for type and/or instance evaluation handler)Overrides default org. Interception point before the execution of a handler. |
| bestMatchingPattern | back to summary |
|---|---|
| private final String bestMatchingPattern | |
| pathWithinMapping | back to summary |
|---|---|
| private final String pathWithinMapping | |
| PathExposingHandlerInterceptor | back to summary |
|---|---|
| public PathExposingHandlerInterceptor(String bestMatchingPattern, String pathWithinMapping) | |
| preHandle | back to summary |
|---|---|
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) Overrides default org. Doc from org. Interception point before the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler. DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response. Note special considerations apply for asynchronous
request processing. For more details see
The default implementation returns
| |
AbstractUrlHandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE attribute.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | preHandle(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object chosen handler to execute, for type and/or instance evaluation handler)Overrides default org. Interception point before the execution of a handler. |
| uriTemplateVariables | back to summary |
|---|---|
| private final Map<String, String> uriTemplateVariables | |
| UriTemplateVariablesHandlerInterceptor | back to summary |
|---|---|
| public UriTemplateVariablesHandlerInterceptor(Map<String, String> uriTemplateVariables) | |
| preHandle | back to summary |
|---|---|
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) Overrides default org. Doc from org. Interception point before the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler. DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response. Note special considerations apply for asynchronous
request processing. For more details see
The default implementation returns
| |