org.springframework.web.reactive.resource

## Class ResourceUrlProvider

- java.lang.Object
- - org.springframework.web.reactive.resource.ResourceUrlProvider

- All Implemented Interfaces:
    EventListener, Aware, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>

      public class ResourceUrlProvider
      extends Object
      implements ApplicationListener<ContextRefreshedEvent>, 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 `ResourceHttpRequestHandler`s to make its decisions.

  Since:
    5.0
  Author:
    Rossen Stoyanchev, Brian Clozel

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceUrlProvider()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `reactor.core.publisher.Mono<String>` | `getForUriString(String uriString, ServerWebExchange exchange)` Get the public resource URL for the given URI string.
    `Map<PathPattern,ResourceWebHandler>` | `getHandlerMap()` Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration.
    `void` | `onApplicationEvent(ContextRefreshedEvent event)` Handle an application event.
    `void` | `registerHandlers(Map<String,ResourceWebHandler> handlerMap)` Manually configure resource handler mappings.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.

    - ### 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

      `forPayload`

- - ### Constructor Detail

    - #### ResourceUrlProvider

          public ResourceUrlProvider()

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)
                                     throws BeansException

      Description copied from interface: `ApplicationContextAware`
      Set 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 after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      Specified by:
        `setApplicationContext` in 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:
        `BeanInitializationException`

    - #### getHandlerMap

          public Map<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(ContextRefreshedEvent event)

      Description copied from interface: `ApplicationListener`
      Handle an application event.
      Specified by:
        `onApplicationEvent` in interface `ApplicationListener<ContextRefreshedEvent>`
      Parameters:
        `event` - the event to respond to

    - #### getForUriString

          public final reactor.core.publisher.Mono<String> getForUriString(String uriString,
                                                                           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