public class ResourceHandlerRegistry extends Object
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.
Constructor and Description |
---|
ResourceHandlerRegistry(ResourceLoader resourceLoader)
Create a new resource handler registry for the given resource loader
(typically an application context).
|
Modifier and Type | Method and Description |
---|---|
ResourceHandlerRegistration |
addResourceHandler(String... patterns)
Add a resource handler for serving static resources based on the specified
URL path patterns.
|
protected AbstractUrlHandlerMapping |
getHandlerMapping()
Return a handler mapping with the mapped resource handlers; or
null in case
of no registrations. |
boolean |
hasMappingForPattern(String pathPattern)
Whether a resource handler has already been registered for the given path pattern.
|
ResourceHandlerRegistry |
setOrder(int order)
Specify the order to use for resource handling relative to other
HandlerMapping s configured in the Spring configuration. |
void |
setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider)
Configure the
ResourceUrlProvider that can be used by
ResourceTransformer instances. |
public ResourceHandlerRegistry(ResourceLoader resourceLoader)
resourceLoader
- the resource loader to usepublic void setResourceUrlProvider(@Nullable ResourceUrlProvider resourceUrlProvider)
ResourceUrlProvider
that can be used by
ResourceTransformer
instances.resourceUrlProvider
- the resource URL provider to usepublic ResourceHandlerRegistration addResourceHandler(String... patterns)
Patterns like "/static/**"
or "/css/{filename:\\w+\\.css}"
are allowed. See PathPattern
for more details on the syntax.
ResourceHandlerRegistration
to use to further configure
the registered resource handlerpublic boolean hasMappingForPattern(String pathPattern)
public ResourceHandlerRegistry setOrder(int order)
HandlerMapping
s configured in the Spring configuration.
The default value used is Integer.MAX_VALUE-1
.
@Nullable protected AbstractUrlHandlerMapping getHandlerMapping()
null
in case
of no registrations.