类 AbstractHandlerMapping
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.handler.AbstractHandlerMapping
- 所有已实现的接口:
Aware,ApplicationContextAware,Ordered,ServletContextAware,HandlerMapping
public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport implements HandlerMapping, Ordered
Abstract base class forHandlerMappingimplementations. Supports ordering, a default handler, handler interceptors, including handler interceptors mapped by path patterns.Note: This base class does not support exposure of the
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE. Support for this attribute is up to concrete subclasses, typically based on request URL mappings.- 从以下版本开始:
- 07.04.2003
- 作者:
- Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
getHandlerInternal(javax.servlet.http.HttpServletRequest),setDefaultHandler(java.lang.Object),setAlwaysUseFullPath(boolean),setUrlDecode(boolean),AntPathMatcher,setInterceptors(java.lang.Object...),HandlerInterceptor
字段概要
从类继承的字段 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
构造器概要
构造器 构造器 说明 AbstractHandlerMapping()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected HandlerInterceptoradaptInterceptor(Object interceptor)Adapt the given interceptor object toHandlerInterceptor.protected voiddetectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors)Detect beans of typeMappedInterceptorand add them to the list of mapped interceptors.protected voidextendInterceptors(List<Object> interceptors)Extension hook that subclasses can override to register additional interceptors, given the configured interceptors (seesetInterceptors(java.lang.Object...)).protected HandlerInterceptor[]getAdaptedInterceptors()Return the adapted interceptors asHandlerInterceptorarray.protected CorsConfigurationgetCorsConfiguration(Object handler, HttpServletRequest request)Retrieve the CORS configuration for the given handler.Map<String,CorsConfiguration>getCorsConfigurations()Get the "global" CORS configurations.protected HandlerExecutionChaingetCorsHandlerExecutionChain(HttpServletRequest request, HandlerExecutionChain chain, CorsConfiguration config)Update the HandlerExecutionChain for CORS-related handling.CorsProcessorgetCorsProcessor()Return the configuredCorsProcessor.ObjectgetDefaultHandler()Return the default handler for this handler mapping, ornullif none.HandlerExecutionChaingetHandler(HttpServletRequest request)Look up a handler for the given request, falling back to the default handler if no specific one is found.protected HandlerExecutionChaingetHandlerExecutionChain(Object handler, HttpServletRequest request)Build aHandlerExecutionChainfor the given handler, including applicable interceptors.protected abstract ObjectgetHandlerInternal(HttpServletRequest request)Look up a handler for the given request, returningnullif no specific one is found.protected MappedInterceptor[]getMappedInterceptors()Return all configuredMappedInterceptors as an array.intgetOrder()Get the order value of this object.PathMatchergetPathMatcher()Return the PathMatcher implementation to use for matching URL paths against registered URL patterns.UrlPathHelpergetUrlPathHelper()Return the UrlPathHelper implementation to use for resolution of lookup paths.protected voidinitApplicationContext()Initializes the interceptors.protected voidinitInterceptors()Initialize the specified interceptors adaptingWebRequestInterceptors toHandlerInterceptor.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath)Set if URL lookup should always use the full path within the current servlet context.voidsetCorsConfigurations(Map<String,CorsConfiguration> corsConfigurations)Set the "global" CORS configurations based on URL patterns.voidsetCorsProcessor(CorsProcessor corsProcessor)Configure a customCorsProcessorto use to apply the matchedCorsConfigurationfor a request.voidsetDefaultHandler(Object defaultHandler)Set the default handler for this handler mapping.voidsetInterceptors(Object... interceptors)Set the interceptors to apply for all handlers mapped by this handler mapping.voidsetOrder(int order)Specify the order value for this HandlerMapping bean.voidsetPathMatcher(PathMatcher pathMatcher)Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.voidsetRemoveSemicolonContent(boolean removeSemicolonContent)Set if ";" (semicolon) content should be stripped from the request URI.voidsetUrlDecode(boolean urlDecode)Set if context path and request URI should be URL-decoded.voidsetUrlPathHelper(UrlPathHelper urlPathHelper)Set the UrlPathHelper to use for resolution of lookup paths.从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
构造器详细资料
AbstractHandlerMapping
public AbstractHandlerMapping()
方法详细资料
setDefaultHandler
public void setDefaultHandler(Object defaultHandler)
Set the default handler for this handler mapping. This handler will be returned if no specific mapping was found.Default is
null, indicating no default handler.
getDefaultHandler
public Object getDefaultHandler()
Return the default handler for this handler mapping, ornullif none.
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use the full path within the current servlet context. Else, the path within the current servlet mapping is used if applicable (that is, in the case of a ".../*" servlet mapping in web.xml).Default is "false".
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.The default value is
true.
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers.
getUrlPathHelper
public UrlPathHelper getUrlPathHelper()
Return the UrlPathHelper implementation to use for resolution of lookup paths.
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher.- 另请参阅:
AntPathMatcher
getPathMatcher
public PathMatcher getPathMatcher()
Return the PathMatcher implementation to use for matching URL paths against registered URL patterns.
setInterceptors
public void setInterceptors(Object... interceptors)
Set the interceptors to apply for all handlers mapped by this handler mapping.Supported interceptor types are HandlerInterceptor, WebRequestInterceptor, and MappedInterceptor. Mapped interceptors apply only to request URLs that match its path patterns. Mapped interceptor beans are also detected by type during initialization.
- 参数:
interceptors- array of handler interceptors- 另请参阅:
adaptInterceptor(java.lang.Object),HandlerInterceptor,WebRequestInterceptor
setCorsConfigurations
public void setCorsConfigurations(Map<String,CorsConfiguration> corsConfigurations)
Set the "global" CORS configurations based on URL patterns. By default the first matching URL pattern is combined with the CORS configuration for the handler, if any.- 从以下版本开始:
- 4.2
getCorsConfigurations
public Map<String,CorsConfiguration> getCorsConfigurations()
Get the "global" CORS configurations.
setCorsProcessor
public void setCorsProcessor(CorsProcessor corsProcessor)
Configure a customCorsProcessorto use to apply the matchedCorsConfigurationfor a request.By default
DefaultCorsProcessoris used.- 从以下版本开始:
- 4.2
getCorsProcessor
public CorsProcessor getCorsProcessor()
Return the configuredCorsProcessor.
setOrder
public void setOrder(int order)
Specify the order value for this HandlerMapping bean.The default value is
Ordered.LOWEST_PRECEDENCE, meaning non-ordered.- 另请参阅:
Ordered.getOrder()
getOrder
public int getOrder()
从接口复制的说明:OrderedGet the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet
load-on-startupvalues).Same order values will result in arbitrary sort positions for the affected objects.
- 指定者:
getOrder在接口中Ordered- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
initApplicationContext
protected void initApplicationContext() throws BeansException
Initializes the interceptors.- 覆盖:
initApplicationContext在类中ApplicationObjectSupport- 抛出:
ApplicationContextException- in case of initialization errorsBeansException- if thrown by ApplicationContext methods- 另请参阅:
extendInterceptors(java.util.List),initInterceptors()
extendInterceptors
protected void extendInterceptors(List<Object> interceptors)
Extension hook that subclasses can override to register additional interceptors, given the configured interceptors (seesetInterceptors(java.lang.Object...)).Will be invoked before
initInterceptors()adapts the specified interceptors intoHandlerInterceptorinstances.The default implementation is empty.
- 参数:
interceptors- the configured interceptor List (nevernull), allowing to add further interceptors before as well as after the existing interceptors
detectMappedInterceptors
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors)
Detect beans of typeMappedInterceptorand add them to the list of mapped interceptors.This is called in addition to any
MappedInterceptors that may have been provided viasetInterceptors(java.lang.Object...), by default adding all beans of typeMappedInterceptorfrom the current context and its ancestors. Subclasses can override and refine this policy.- 参数:
mappedInterceptors- an empty list to add to
initInterceptors
protected void initInterceptors()
Initialize the specified interceptors adaptingWebRequestInterceptors toHandlerInterceptor.
adaptInterceptor
protected HandlerInterceptor adaptInterceptor(Object interceptor)
Adapt the given interceptor object toHandlerInterceptor.By default, the supported interceptor types are
HandlerInterceptorandWebRequestInterceptor. Each givenWebRequestInterceptoris wrapped withWebRequestHandlerInterceptorAdapter.- 参数:
interceptor- the interceptor- 返回:
- the interceptor downcast or adapted to HandlerInterceptor
- 另请参阅:
HandlerInterceptor,WebRequestInterceptor,WebRequestHandlerInterceptorAdapter
getAdaptedInterceptors
protected final HandlerInterceptor[] getAdaptedInterceptors()
Return the adapted interceptors asHandlerInterceptorarray.- 返回:
- the array of
HandlerInterceptors, ornullif none
getMappedInterceptors
protected final MappedInterceptor[] getMappedInterceptors()
Return all configuredMappedInterceptors as an array.- 返回:
- the array of
MappedInterceptors, ornullif none
getHandler
public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception
Look up a handler for the given request, falling back to the default handler if no specific one is found.- 指定者:
getHandler在接口中HandlerMapping- 参数:
request- current HTTP request- 返回:
- the corresponding handler instance, or the default handler
- 抛出:
Exception- if there is an internal error- 另请参阅:
getHandlerInternal(javax.servlet.http.HttpServletRequest)
getHandlerInternal
protected abstract Object getHandlerInternal(HttpServletRequest request) throws Exception
Look up a handler for the given request, returningnullif no specific one is found. This method is called bygetHandler(javax.servlet.http.HttpServletRequest); anullreturn 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
getCorsConfigurations(),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.- 参数:
request- current HTTP request- 返回:
- the corresponding handler instance, or
nullif none found - 抛出:
Exception- if there is an internal error
getHandlerExecutionChain
protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request)
Build aHandlerExecutionChainfor the given handler, including applicable interceptors.The default implementation builds a standard
HandlerExecutionChainwith the given handler, the common interceptors of the handler mapping, and anyMappedInterceptorsmatching to the current request URL. Interceptors are added in the order they were registered. Subclasses may override this in order to extend/rearrange the list of interceptors.NOTE: The passed-in handler object may be a raw handler or a pre-built
HandlerExecutionChain. This method should handle those two cases explicitly, either building a newHandlerExecutionChainor extending the existing chain.For simply adding an interceptor in a custom subclass, consider calling
super.getHandlerExecutionChain(handler, request)and invokingHandlerExecutionChain.addInterceptor(org.springframework.web.servlet.HandlerInterceptor)on the returned chain object.- 参数:
handler- the resolved handler instance (nevernull)request- current HTTP request- 返回:
- the HandlerExecutionChain (never
null) - 另请参阅:
getAdaptedInterceptors()
getCorsConfiguration
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request)
Retrieve the CORS configuration for the given handler.- 参数:
handler- the handler to check (nevernull).request- the current request.- 返回:
- the CORS configuration for the handler, or
nullif none - 从以下版本开始:
- 4.2
getCorsHandlerExecutionChain
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request, HandlerExecutionChain chain, CorsConfiguration config)
Update the HandlerExecutionChain for CORS-related handling.For pre-flight requests, the default implementation replaces the selected handler with a simple HttpRequestHandler that invokes the configured
setCorsProcessor(org.springframework.web.cors.CorsProcessor).For actual requests, the default implementation inserts a HandlerInterceptor that makes CORS-related checks and adds CORS headers.
- 参数:
request- the current requestchain- the handler chainconfig- the applicable CORS configuration (possiblynull)- 从以下版本开始:
- 4.2