类 AbstractUrlHandlerMapping
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.handler.AbstractHandlerMapping
- org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
- 所有已实现的接口:
Aware
,ApplicationContextAware
,Ordered
,ServletContextAware
,MatchableHandlerMapping
,HandlerMapping
public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping
Abstract base class for URL-mappedHandlerMapping
implementations. Provides infrastructure for mapping handlers to URLs and configurable URL lookup. For information on the latter, see "alwaysUseFullPath" property.Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" pattern matches both "/test" and "/team", "/test/*" matches all paths in the "/test" directory, "/test/**" matches all paths below "/test". For details, see the
AntPathMatcher
javadoc.Will search all path patterns to find the most exact match for the current request path. The most exact match is defined as the longest path pattern that matches the current request path.
- 从以下版本开始:
- 16.04.2003
- 作者:
- Juergen Hoeller, Arjen Poutsma
字段概要
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.web.servlet.HandlerMapping
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 AbstractUrlHandlerMapping()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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, theHandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
, as well as theHandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE
before executing the handler.protected void
exposePathWithinMapping(String bestMatchingPattern, String pathWithinMapping, HttpServletRequest request)
Expose the path within the current mapping as request attribute.protected void
exposeUriTemplateVariables(Map<String,String> uriTemplateVariables, HttpServletRequest request)
Expose the URI templates variables as request attribute.protected Object
getHandlerInternal(HttpServletRequest request)
Look up a handler for the URL path of the given request.Map<String,Object>
getHandlerMap()
Return the registered handlers as an unmodifiable Map, with the registered path as key and the handler object (or handler bean name in case of a lazy-init handler) as value.Object
getRootHandler()
Return the root handler for this handler mapping (registered for "/"), ornull
if none.protected Object
lookupHandler(String urlPath, HttpServletRequest request)
Look up a handler instance for the given URL path.RequestMatchResult
match(HttpServletRequest request, String pattern)
Determine whether the given request matches the request criteria.protected void
registerHandler(String[] urlPaths, String beanName)
Register the specified handler for the given URL paths.protected void
registerHandler(String urlPath, Object handler)
Register the specified handler for the given URL path.void
setLazyInitHandlers(boolean lazyInitHandlers)
Set whether to lazily initialize handlers.void
setRootHandler(Object rootHandler)
Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/").void
setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.protected boolean
supportsTypeLevelMappings()
Indicates whether this handler mapping support type-level mappings.boolean
useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.protected void
validateHandler(Object handler, HttpServletRequest request)
Validate the given handler against the current request.从类继承的方法 org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getCorsConfiguration, getCorsConfigurations, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initApplicationContext, initInterceptors, setAlwaysUseFullPath, setCorsConfigurations, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.web.servlet.HandlerMapping
getHandler
构造器详细资料
AbstractUrlHandlerMapping
public AbstractUrlHandlerMapping()
方法详细资料
setRootHandler
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
null
, indicating no root handler.
getRootHandler
public Object getRootHandler()
Return the root handler for this handler mapping (registered for "/"), ornull
if none.
setUseTrailingSlashMatch
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
false
.
useTrailingSlashMatch
public boolean useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
setLazyInitHandlers
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.
getHandlerInternal
protected Object getHandlerInternal(HttpServletRequest request) throws Exception
Look up a handler for the URL path of the given request.- 指定者:
getHandlerInternal
在类中AbstractHandlerMapping
- 参数:
request
- current HTTP request- 返回:
- the handler instance, or
null
if none found - 抛出:
Exception
- if there is an internal error
lookupHandler
protected Object lookupHandler(String urlPath, HttpServletRequest request) throws Exception
Look up a handler instance for the given URL path.Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
Looks for the most exact pattern, where most exact is defined as the longest path pattern.
- 参数:
urlPath
- the URL the bean is mapped torequest
- current HTTP request (to expose the path within the mapping to)- 返回:
- the associated handler instance, or
null
if not found - 抛出:
Exception
- 另请参阅:
exposePathWithinMapping(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
,AntPathMatcher
validateHandler
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.
- 参数:
handler
- the handler object to validaterequest
- current HTTP request- 抛出:
Exception
- if validation failed
buildPathExposingHandler
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, theHandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
, as well as theHandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE
before executing the handler.The default implementation builds a
HandlerExecutionChain
with a special interceptor that exposes the path attribute and uri template variables- 参数:
rawHandler
- the raw handler to exposepathWithinMapping
- the path to expose before executing the handleruriTemplateVariables
- the URI template variables, can benull
if no variables found- 返回:
- the final handler object
exposePathWithinMapping
protected void exposePathWithinMapping(String bestMatchingPattern, String pathWithinMapping, HttpServletRequest request)
Expose the path within the current mapping as request attribute.- 参数:
pathWithinMapping
- the path within the current mappingrequest
- the request to expose the path to- 另请参阅:
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
exposeUriTemplateVariables
protected void exposeUriTemplateVariables(Map<String,String> uriTemplateVariables, HttpServletRequest request)
Expose the URI templates variables as request attribute.- 参数:
uriTemplateVariables
- the URI template variablesrequest
- the request to expose the path to- 另请参阅:
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
match
public RequestMatchResult match(HttpServletRequest request, String pattern)
从接口复制的说明:MatchableHandlerMapping
Determine whether the given request matches the request criteria.- 指定者:
match
在接口中MatchableHandlerMapping
- 参数:
request
- the current requestpattern
- the pattern to match- 返回:
- the result from request matching, or
null
if none
registerHandler
protected void registerHandler(String[] urlPaths, String beanName) throws BeansException, IllegalStateException
Register the specified handler for the given URL paths.- 参数:
urlPaths
- the URLs that the bean should be mapped tobeanName
- the name of the handler bean- 抛出:
BeansException
- if the handler couldn't be registeredIllegalStateException
- if there is a conflicting handler registered
registerHandler
protected void registerHandler(String urlPath, Object handler) throws BeansException, IllegalStateException
Register the specified handler for the given URL path.- 参数:
urlPath
- the URL the bean should be mapped tohandler
- the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)- 抛出:
BeansException
- if the handler couldn't be registeredIllegalStateException
- if there is a conflicting handler registered
getHandlerMap
public final Map<String,Object> getHandlerMap()
Return the registered handlers as an unmodifiable Map, with the registered path as key and the handler object (or handler bean name in case of a lazy-init handler) as value.
supportsTypeLevelMappings
protected boolean supportsTypeLevelMappings()
Indicates whether this handler mapping support type-level mappings. Default tofalse
.