public class ResourceHandlerRegistry
extends java.lang.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.
DefaultServletHandlerConfigurer
Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
appContext |
private int |
order |
private java.util.List<ResourceHandlerRegistration> |
registrations |
private java.util.List<ResourceResolver> |
resourceResolvers |
private java.util.List<ResourceTransformer> |
resourceTransformers |
private ServletContext |
servletContext |
Constructor and Description |
---|
ResourceHandlerRegistry(ApplicationContext applicationContext,
ServletContext servletContext) |
Modifier and Type | Method and Description |
---|---|
ResourceHandlerRegistration |
addResourceHandler(java.lang.String... pathPatterns)
Add a resource handler for serving static resources based on the specified URL path patterns.
|
protected AbstractHandlerMapping |
getHandlerMapping()
Return a handler mapping with the mapped resource handlers; or
null in case of no registrations. |
boolean |
hasMappingForPattern(java.lang.String pathPattern)
Whether a resource handler has already been registered for the given pathPattern.
|
ResourceHandlerRegistry |
setOrder(int order)
Specify the order to use for resource handling relative to other
HandlerMapping s configured in
the Spring MVC application context. |
ResourceHandlerRegistry |
setResourceResolvers(ResourceResolver... resolvers)
Configure the
ResourceResolver s to use by default, that is in
resource handlers aren't already configured explicitly with resolvers. |
ResourceHandlerRegistry |
setResourceTransformers(ResourceTransformer... transformers)
Configure the
ResourceTransformer s to use by default, that is in
resource handlers aren't already configured explicitly with transformers. |
private final ServletContext servletContext
private final ApplicationContext appContext
private final java.util.List<ResourceHandlerRegistration> registrations
private java.util.List<ResourceResolver> resourceResolvers
private java.util.List<ResourceTransformer> resourceTransformers
private int order
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext)
public ResourceHandlerRegistration addResourceHandler(java.lang.String... pathPatterns)
ResourceHandlerRegistration
to use to further configure the registered resource handler.public boolean hasMappingForPattern(java.lang.String pathPattern)
public ResourceHandlerRegistry setOrder(int order)
HandlerMapping
s configured in
the Spring MVC application context. The default value used is Integer.MAX_VALUE-1
.public ResourceHandlerRegistry setResourceResolvers(ResourceResolver... resolvers)
ResourceResolver
s to use by default, that is in
resource handlers aren't already configured explicitly with resolvers.public ResourceHandlerRegistry setResourceTransformers(ResourceTransformer... transformers)
ResourceTransformer
s to use by default, that is in
resource handlers aren't already configured explicitly with transformers.protected AbstractHandlerMapping getHandlerMapping()
null
in case of no registrations.