Class ResourceUrlProvider
java.lang.Object
org.springframework.web.servlet.resource.ResourceUrlProvider
- All Implemented Interfaces:
EventListener
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public class ResourceUrlProvider
extends Object
implements org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware
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 configured
ResourceHttpRequestHandler
s to make its decisions.
- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Brian Clozel
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
detectResourceHandlers
(org.springframework.context.ApplicationContext appContext) 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.getForRequestUrl
(HttpServletRequest request, String requestUrl) A variation ongetForLookupPath(String)
that accepts a full request URL path (i.e.Return the resource mappings, either manually configured or auto-detected when the SpringApplicationContext
is refreshed.org.springframework.util.PathMatcher
Deprecated, for removal: This API element is subject to removal in a future version.org.springframework.web.util.UrlPathHelper
Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules.boolean
Returnfalse
if resource mappings were manually configured,true
otherwise.void
onApplicationEvent
(org.springframework.context.event.ContextRefreshedEvent event) void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) void
setHandlerMap
(@Nullable Map<String, ResourceHttpRequestHandler> handlerMap) Manually configure the resource mappings.void
setPathMatcher
(org.springframework.util.PathMatcher pathMatcher) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules.void
setUrlPathHelper
(org.springframework.web.util.UrlPathHelper urlPathHelper) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
ResourceUrlProvider
public ResourceUrlProvider()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setUrlPathHelper
@Deprecated(since="7.0", forRemoval=true) public void setUrlPathHelper(org.springframework.web.util.UrlPathHelper urlPathHelper) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules. After the deprecation phase, it will no longer be possible to set a customized PathMatcher instance.Configure aUrlPathHelper
to use ingetForRequestUrl(jakarta.servlet.http.HttpServletRequest, String)
in order to derive the lookup path for a target request URL path. -
getUrlPathHelper
@Deprecated(since="7.0", forRemoval=true) public org.springframework.web.util.UrlPathHelper getUrlPathHelper()Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules. After the deprecation phase, it will no longer be possible to set a customized PathMatcher instance.Return the configuredUrlPathHelper
.- Since:
- 4.2.8
-
setPathMatcher
@Deprecated(since="7.0", forRemoval=true) public void setPathMatcher(org.springframework.util.PathMatcher pathMatcher) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules. After the deprecation phase, it will no longer be possible to set a customized PathMatcher instance.Configure aPathMatcher
to use when comparing target lookup path against resource mappings. -
getPathMatcher
@Deprecated(since="7.0", forRemoval=true) public org.springframework.util.PathMatcher getPathMatcher()Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules. After the deprecation phase, it will no longer be possible to set a customized PathMatcher instance.Return the configuredPathMatcher
. -
setHandlerMap
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
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(org.springframework.context.event.ContextRefreshedEvent event) - Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
detectResourceHandlers
protected void detectResourceHandlers(org.springframework.context.ApplicationContext appContext) -
getForRequestUrl
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.- Parameters:
request
- the current requestrequestUrl
- the request URL path to resolve- Returns:
- the resolved public URL path, or
null
if unresolved
-
getForLookupPath
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.
- Parameters:
lookupPath
- the lookup path to check- Returns:
- the resolved public URL path, or
null
if unresolved
-
PathMatcher
andUrlPathHelper
is deprecated for use at runtime in web modules.