Class ResourceUrlProvider

  • java.lang.Object
    • org.springframework.web.servlet.resource.ResourceUrlProvider
  • All Implemented Interfaces:
    java.util.EventListener, ApplicationListener<ContextRefreshedEvent>

    public class ResourceUrlProvider
    extends java.lang.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 configured ResourceHttpRequestHandlers to make its decisions.

    Rossen Stoyanchev
    • Field Detail

      • logger

        protected final Log logger
    • Constructor Detail

      • ResourceUrlProvider

        public ResourceUrlProvider()
    • Method Detail

      • getUrlPathHelper

        public UrlPathHelper getUrlPathHelper()
        Return the configured UrlPathHelper.
      • setPathMatcher

        public void setPathMatcher(PathMatcher pathMatcher)
        Configure a PathMatcher to use when comparing target lookup path against resource mappings.
      • getPathMatcher

        public PathMatcher getPathMatcher()
        Return the configured PathMatcher.
      • setHandlerMap

        public void setHandlerMap(@Nullable
                                  java.util.Map<java.lang.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 java.util.Map<java.lang.String,ResourceHttpRequestHandler> getHandlerMap()
        Return the resource mappings, either manually configured or auto-detected when the Spring ApplicationContext is refreshed.
      • isAutodetect

        public boolean isAutodetect()
        Return false if resource mappings were manually configured, true otherwise.
      • detectResourceHandlers

        protected void detectResourceHandlers(ApplicationContext appContext)
      • getForRequestUrl

        public final java.lang.String getForRequestUrl(HttpServletRequest request,
                                                                 java.lang.String requestUrl)
        A variation on getForLookupPath(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 request
        requestUrl - the request URL path to resolve
        the resolved public URL path, or null if unresolved
      • getForLookupPath

        public final java.lang.String getForLookupPath(java.lang.String lookupPath)
        Compare the given path against configured resource handler mappings and if a match is found use the ResourceResolver chain of the matched ResourceHttpRequestHandler 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