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
ResourceHttpRequestHandler
s to make its decisions.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Brian Clozel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal reactor.core.publisher.Mono<String>
getForUriString
(String uriString, org.springframework.web.server.ServerWebExchange exchange) Get the public resource URL for the given URI string.Map<org.springframework.web.util.pattern.PathPattern,
ResourceWebHandler> Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration.void
onApplicationEvent
(org.springframework.context.event.ContextRefreshedEvent event) void
registerHandlers
(Map<String, ResourceWebHandler> handlerMap) Manually configure resource handler mappings.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext)
-
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
-
getHandlerMap
Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration. -
registerHandlers
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 interfaceorg.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 transformexchange
- the current exchange- Returns:
- the resolved public resource URL path, or empty if unresolved
-