public class ResourceUrlProvider extends Object implements ApplicationListener<ContextRefreshedEvent>, ApplicationContextAware
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.
Constructor and Description |
---|
ResourceUrlProvider() |
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.
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
ApplicationContextAware
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.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectApplicationContextException
- in case of context initialization errorsBeansException
- if thrown by application context methodsBeanInitializationException
public Map<PathPattern,ResourceWebHandler> getHandlerMap()
public void registerHandlers(Map<String,ResourceWebHandler> handlerMap)
Note: by default resource mappings are auto-detected
from the Spring ApplicationContext
. If this property is used,
auto-detection is turned off.
public void onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond topublic final reactor.core.publisher.Mono<String> getForUriString(String uriString, ServerWebExchange exchange)
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.
uriString
- the URI string to transformexchange
- the current exchange