类 ResourceUrlProvider
- java.lang.Object
- org.springframework.web.servlet.resource.ResourceUrlProvider
public class ResourceUrlProvider extends Object implements ApplicationListener<ContextRefreshedEvent>
A central component to use to obtain the public URL path that clients should use to access a static resource.This class is aware of Spring MVC handler mappings used to serve static resources and uses the
ResourceResolver
chains of the configuredResourceHttpRequestHandler
s to make its decisions.- 从以下版本开始:
- 4.1
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 ResourceUrlProvider()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected void
detectResourceHandlers(ApplicationContext appContext)
String
getForLookupPath(String lookupPath)
Compare the given path against configured resource handler mappings and if a match is found use theResourceResolver
chain of the matchedResourceHttpRequestHandler
to resolve the URL path to expose for public use.String
getForRequestUrl(HttpServletRequest request, String requestUrl)
A variation ongetForLookupPath(String)
that accepts a full request URL path (i.e. including context and servlet path) and returns the full request URL path to expose for public use.Map<String,ResourceHttpRequestHandler>
getHandlerMap()
Return the resource mappings, either manually configured or auto-detected when the SpringApplicationContext
is refreshed.UrlPathHelper
getPathHelper()
已过时。as of Spring 4.2.8, in favor ofgetUrlPathHelper()
PathMatcher
getPathMatcher()
Return the configuredPathMatcher
.UrlPathHelper
getUrlPathHelper()
Return the configuredUrlPathHelper
.boolean
isAutodetect()
Returnfalse
if resource mappings were manually configured,true
otherwise.void
onApplicationEvent(ContextRefreshedEvent event)
Handle an application event.void
setHandlerMap(Map<String,ResourceHttpRequestHandler> handlerMap)
Manually configure the resource mappings.void
setPathMatcher(PathMatcher pathMatcher)
Configure aPathMatcher
to use when comparing target lookup path against resource mappings.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Configure aUrlPathHelper
to use ingetForRequestUrl(javax.servlet.http.HttpServletRequest, String)
in order to derive the lookup path for a target request URL path.
构造器详细资料
ResourceUrlProvider
public ResourceUrlProvider()
方法详细资料
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Configure aUrlPathHelper
to use ingetForRequestUrl(javax.servlet.http.HttpServletRequest, String)
in order to derive the lookup path for a target request URL path.
getUrlPathHelper
public UrlPathHelper getUrlPathHelper()
Return the configuredUrlPathHelper
.- 从以下版本开始:
- 4.2.8
getPathHelper
@Deprecated public UrlPathHelper getPathHelper()
已过时。as of Spring 4.2.8, in favor ofgetUrlPathHelper()
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Configure aPathMatcher
to use when comparing target lookup path against resource mappings.
getPathMatcher
public PathMatcher getPathMatcher()
Return the configuredPathMatcher
.
setHandlerMap
public void setHandlerMap(Map<String,ResourceHttpRequestHandler> handlerMap)
Manually configure the resource mappings.Note: by default resource mappings are auto-detected from the Spring
ApplicationContext
. However if this property is used, the auto-detection is turned off.
getHandlerMap
public Map<String,ResourceHttpRequestHandler> getHandlerMap()
Return the resource mappings, either manually configured or auto-detected when the SpringApplicationContext
is refreshed.
isAutodetect
public boolean isAutodetect()
Returnfalse
if resource mappings were manually configured,true
otherwise.
onApplicationEvent
public void onApplicationEvent(ContextRefreshedEvent event)
从接口复制的说明:ApplicationListener
Handle an application event.- 指定者:
onApplicationEvent
在接口中ApplicationListener<ContextRefreshedEvent>
- 参数:
event
- the event to respond to
detectResourceHandlers
protected void detectResourceHandlers(ApplicationContext appContext)
getForRequestUrl
public final String getForRequestUrl(HttpServletRequest request, String requestUrl)
A variation ongetForLookupPath(String)
that accepts a full request URL path (i.e. including context and servlet path) and returns the full request URL path to expose for public use.- 参数:
request
- the current requestrequestUrl
- the request URL path to resolve- 返回:
- the resolved public URL path, or
null
if unresolved
getForLookupPath
public final String getForLookupPath(String lookupPath)
Compare the given path against configured resource handler mappings and if a match is found use theResourceResolver
chain of the matchedResourceHttpRequestHandler
to resolve the URL path to expose for public use.It is expected that the given path is what Spring MVC would use for request mapping purposes, i.e. excluding context and servlet path portions.
If several handler mappings match, the handler used will be the one configured with the most specific pattern.
- 参数:
lookupPath
- the lookup path to check- 返回:
- the resolved public URL path, or
null
if unresolved