Class ResourceHandlerRegistry
java.lang.Object
org.springframework.web.reactive.config.ResourceHandlerRegistry
Stores registrations of resource handlers for serving static resources such
as images, css files and others through Spring WebFlux including setting cache
headers optimized for efficient loading in a web browser. Resources can be
served out of locations under web application root, from the classpath, and
others.
To create a resource handler, use addResourceHandler(String...)
providing the URL path patterns for which the handler should be invoked to
serve static resources (e.g. "/resources/**").
Then use additional methods on the returned
ResourceHandlerRegistration to add one or more locations from which
to serve static content from (e.g. {"/",
"classpath:/META-INF/public-web-resources/"}) or to specify a cache
period for served resources.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Brian Clozel
-
Constructor Summary
ConstructorsConstructorDescriptionResourceHandlerRegistry(ResourceLoader resourceLoader) Create a new resource handler registry for the given resource loader (typically an application context). -
Method Summary
Modifier and TypeMethodDescriptionaddResourceHandler(String... patterns) Add a resource handler for serving static resources based on the specified URL path patterns.protected AbstractUrlHandlerMappingReturn a handler mapping with the mapped resource handlers; ornullin case of no registrations.booleanhasMappingForPattern(String pathPattern) Whether a resource handler has already been registered for the given path pattern.setOrder(int order) Specify the order to use for resource handling relative to otherHandlerMappings configured in the Spring configuration.voidsetResourceUrlProvider(ResourceUrlProvider resourceUrlProvider) Configure theResourceUrlProviderthat can be used byResourceTransformerinstances.
-
Constructor Details
-
ResourceHandlerRegistry
Create a new resource handler registry for the given resource loader (typically an application context).- Parameters:
resourceLoader- the resource loader to use
-
-
Method Details
-
setResourceUrlProvider
Configure theResourceUrlProviderthat can be used byResourceTransformerinstances.- Parameters:
resourceUrlProvider- the resource URL provider to use- Since:
- 5.0.11
-
addResourceHandler
Add a resource handler for serving static resources based on the specified URL path patterns. The handler will be invoked for every incoming request that matches to one of the specified path patterns.Patterns like
"/static/**"or"/css/{filename:\\w+\\.css}"are allowed. SeePathPatternfor more details on the syntax.- Returns:
- a
ResourceHandlerRegistrationto use to further configure the registered resource handler
-
hasMappingForPattern
Whether a resource handler has already been registered for the given path pattern. -
setOrder
Specify the order to use for resource handling relative to otherHandlerMappings configured in the Spring configuration.The default value used is
Integer.MAX_VALUE-1. -
getHandlerMapping
Return a handler mapping with the mapped resource handlers; ornullin case of no registrations.
-