Class ResourceUrlProvider
- All Implemented Interfaces:
- EventListener,- Aware,- ApplicationContextAware,- ApplicationListener<ContextRefreshedEvent>
This class is aware of Spring MVC handler mappings used to serve static
 resources and uses the ResourceResolver chains of the configured
 ResourceHttpRequestHandlers to make its decisions.
- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Brian Clozel
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voiddetectResourceHandlers(ApplicationContext appContext) final StringgetForLookupPath(String lookupPath) Compare the given path against configured resource handler mappings and if a match is found use theResourceResolverchain of the matchedResourceHttpRequestHandlerto resolve the URL path to expose for public use.final StringgetForRequestUrl(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 SpringApplicationContextis refreshed.Return the configuredPathMatcher.Return the configuredUrlPathHelper.booleanReturnfalseif resource mappings were manually configured,trueotherwise.voidHandle an application event.voidsetApplicationContext(ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.voidsetHandlerMap(Map<String, ResourceHttpRequestHandler> handlerMap) Manually configure the resource mappings.voidsetPathMatcher(PathMatcher pathMatcher) Configure aPathMatcherto use when comparing target lookup path against resource mappings.voidsetUrlPathHelper(UrlPathHelper urlPathHelper) Configure aUrlPathHelperto use ingetForRequestUrl(jakarta.servlet.http.HttpServletRequest, String)in order to derive the lookup path for a target request URL path.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListenersupportsAsyncExecution
- 
Field Details- 
logger
 
- 
- 
Constructor Details- 
ResourceUrlProviderpublic ResourceUrlProvider()
 
- 
- 
Method Details- 
setApplicationContextDescription copied from interface:ApplicationContextAwareSet the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Parameters:
- applicationContext- the ApplicationContext object to be used by this object
- Throws:
- ApplicationContextException- in case of context initialization errors
- BeansException- if thrown by application context methods
- See Also:
 
- 
setUrlPathHelperConfigure aUrlPathHelperto use ingetForRequestUrl(jakarta.servlet.http.HttpServletRequest, String)in order to derive the lookup path for a target request URL path.
- 
getUrlPathHelperReturn the configuredUrlPathHelper.- Since:
- 4.2.8
 
- 
setPathMatcherConfigure aPathMatcherto use when comparing target lookup path against resource mappings.
- 
getPathMatcherReturn the configuredPathMatcher.
- 
setHandlerMapManually 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.
- 
getHandlerMapReturn the resource mappings, either manually configured or auto-detected when the SpringApplicationContextis refreshed.
- 
isAutodetectpublic boolean isAutodetect()Returnfalseif resource mappings were manually configured,trueotherwise.
- 
onApplicationEventDescription copied from interface:ApplicationListenerHandle an application event.- Specified by:
- onApplicationEventin interface- ApplicationListener<ContextRefreshedEvent>
- Parameters:
- event- the event to respond to
 
- 
detectResourceHandlers
- 
getForRequestUrlA 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 request
- requestUrl- the request URL path to resolve
- Returns:
- the resolved public URL path, or nullif unresolved
 
- 
getForLookupPathCompare the given path against configured resource handler mappings and if a match is found use theResourceResolverchain of the matchedResourceHttpRequestHandlerto 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 nullif unresolved
 
 
-