public class ResourceHandlerRegistration extends Object
Constructor and Description |
---|
ResourceHandlerRegistration(ResourceLoader resourceLoader,
String... pathPatterns)
Create a
ResourceHandlerRegistration instance. |
Modifier and Type | Method and Description |
---|---|
ResourceHandlerRegistration |
addResourceLocations(String... resourceLocations)
Add one or more resource locations from which to serve static content.
|
protected String[] |
getPathPatterns()
Returns the URL path patterns for the resource handler.
|
protected ResourceWebHandler |
getRequestHandler()
Returns a
ResourceWebHandler instance. |
ResourceChainRegistration |
resourceChain(boolean cacheResources)
Configure a chain of resource resolvers and transformers to use.
|
ResourceChainRegistration |
resourceChain(boolean cacheResources,
Cache cache)
Configure a chain of resource resolvers and transformers to use.
|
ResourceHandlerRegistration |
setCacheControl(CacheControl cacheControl)
Specify the
CacheControl which should be used
by the resource handler. |
void |
setMediaTypes(Map<String,MediaType> mediaTypes)
Add mappings between file extensions extracted from the filename of static
Resource s and the media types to use for the response. |
ResourceHandlerRegistration |
setOptimizeLocations(boolean optimizeLocations)
Set whether to optimize the specified locations through an existence check on startup,
filtering non-existing directories upfront so that they do not have to be checked
on every resource access.
|
ResourceHandlerRegistration |
setUseLastModified(boolean useLastModified)
Set whether the
Resource.lastModified() information should be used to drive HTTP responses. |
public ResourceHandlerRegistration(ResourceLoader resourceLoader, String... pathPatterns)
ResourceHandlerRegistration
instance.resourceLoader
- a resource loader for turning a String location
into a Resource
pathPatterns
- one or more resource URL path patternspublic ResourceHandlerRegistration addResourceLocations(String... resourceLocations)
Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list, and the locations will be checked for a given resource in the order specified.
For example, "/", "classpath:/META-INF/public-web-resources/"
allows resources to be served both from the web application root and from
any JAR on the classpath that contains a /META-INF/public-web-resources/
directory, with resources in the web application root taking precedence.
ResourceHandlerRegistration
instance, for
chained method invocationpublic ResourceHandlerRegistration setCacheControl(CacheControl cacheControl)
CacheControl
which should be used
by the resource handler.cacheControl
- the CacheControl configuration to useResourceHandlerRegistration
instance, for
chained method invocationpublic ResourceHandlerRegistration setUseLastModified(boolean useLastModified)
Resource.lastModified()
information should be used to drive HTTP responses.
This configuration is set to true
by default.
useLastModified
- whether the "last modified" resource information should be usedResourceHandlerRegistration
instance, for chained method invocationResourceWebHandler.setUseLastModified(boolean)
public ResourceHandlerRegistration setOptimizeLocations(boolean optimizeLocations)
The default is false
, for defensiveness against zip files without directory
entries which are unable to expose the existence of a directory upfront. Switch this flag to
true
for optimized access in case of a consistent jar layout with directory entries.
optimizeLocations
- whether to optimize the locations through an existence check on startupResourceHandlerRegistration
instance, for chained method invocationResourceWebHandler.setOptimizeLocations(boolean)
public ResourceChainRegistration resourceChain(boolean cacheResources)
If this method is not invoked, by default only a simple
PathResourceResolver
is used in order to match URL paths to
resources under the configured locations.
cacheResources
- whether to cache the result of resource resolution;
setting this to "true" is recommended for production (and "false" for
development, especially when applying a version strategy)ResourceHandlerRegistration
instance, for
chained method invocationpublic ResourceChainRegistration resourceChain(boolean cacheResources, Cache cache)
If this method is not invoked, by default only a simple
PathResourceResolver
is used in order to match URL paths to
resources under the configured locations.
cacheResources
- whether to cache the result of resource resolution;
setting this to "true" is recommended for production (and "false" for
development, especially when applying a version strategycache
- the cache to use for storing resolved and transformed resources;
by default a ConcurrentMapCache
is used. Since Resources aren't serializable and can be dependent on the
application host, one should not use a distributed cache but rather an
in-memory cache.ResourceHandlerRegistration
instance, for chained method invocationpublic void setMediaTypes(Map<String,MediaType> mediaTypes)
Resource
s and the media types to use for the response.
Use of this method is typically not necessary since mappings can be
also determined via MediaTypeFactory.getMediaType(Resource)
.
mediaTypes
- media type mappingsprotected String[] getPathPatterns()
protected ResourceWebHandler getRequestHandler()
ResourceWebHandler
instance.