Class ResourceUrlProvider

java.lang.Object
org.springframework.web.reactive.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 WebFlux handler mappings used to serve static resources and uses the ResourceResolver chains of the configured ResourceHttpRequestHandlers to make its decisions.

Since:
5.0
Author:
Rossen Stoyanchev, Brian Clozel
  • 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 interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getHandlerMap

      public Map<org.springframework.web.util.pattern.PathPattern,ResourceWebHandler> getHandlerMap()
      Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration.
    • registerHandlers

      public void registerHandlers(Map<String,ResourceWebHandler> handlerMap)
      Manually configure resource handler mappings.

      Note: by default resource mappings are auto-detected from the Spring ApplicationContext. If this property is used, auto-detection is turned off.

    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
    • getForUriString

      public final reactor.core.publisher.Mono<String> getForUriString(String uriString, org.springframework.web.server.ServerWebExchange exchange)
      Get the public resource URL for the given URI string.

      The URI string is expected to be a path and if it contains a query or fragment those will be preserved in the resulting public resource URL.

      Parameters:
      uriString - the URI string to transform
      exchange - the current exchange
      Returns:
      the resolved public resource URL path, or empty if unresolved