Class ResourceUrlProvider
- java.lang.Object
- org.springframework.web.reactive.resource.ResourceUrlProvider
- All Implemented Interfaces:
EventListener,ApplicationListener<ContextRefreshedEvent>
public class ResourceUrlProvider extends 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 WebFlux handler mappings used to serve static resources and uses the
ResourceResolverchains of the configuredResourceHttpRequestHandlers to make its decisions.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ResourceUrlProvider()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.voidonApplicationEvent(ContextRefreshedEvent event)Handle an application event.voidregisterHandlers(Map<String,ResourceWebHandler> handlerMap)Manually configure resource handler mappings.
Constructor Detail
ResourceUrlProvider
public ResourceUrlProvider()
Method Detail
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:ApplicationListenerHandle an application event.- Specified by:
onApplicationEventin interfaceApplicationListener<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 transformexchange- the current exchange- Returns:
- the resolved public resource URL path, or empty if unresolved