public class ResourceHandlerRegistration extends Object
Constructor and Description |
---|
ResourceHandlerRegistration(ResourceLoader resourceLoader,
String... pathPatterns)
Create a
ResourceHandlerRegistration instance. |
Modifier and Type | Method and Description |
---|---|
ResourceHandlerRegistration |
addResolver(ResourceResolver resolver)
Add a
ResourceResolver to the chain, allowing to resolve server-side resources from
HTTP requests. |
ResourceHandlerRegistration |
addResourceLocations(String... resourceLocations)
Add one or more resource locations from which to serve static content.
|
ResourceHandlerRegistration |
addTransformer(ResourceTransformer transformer)
Add a
ResourceTransformer to the chain, allowing to transform the content
of server-side resources when serving them to HTTP clients. |
ResourceHandlerRegistration |
addVersion(String fixedVersion,
String... pathPatterns)
Apply Resource Versioning on the matching resources using a
FixedVersionStrategy . |
ResourceHandlerRegistration |
addVersionHash(String... pathPatterns)
Apply Resource Versioning on the matching resources using a
ContentVersionStrategy . |
ResourceHandlerRegistration |
addVersionStrategy(VersionStrategy strategy,
String... pathPatterns)
Apply Resource Versioning on the matching resources; this will update resources' URLs to include
a version string calculated by a
VersionStrategy . |
ResourceHandlerRegistration |
enableDevMode()
Disable automatic registration of caching Resolver/Transformer, thus disabling
Resource caching
if no caching Resolver/Transformer was manually registered. |
protected String[] |
getPathPatterns()
Returns the URL path patterns for the resource handler.
|
protected ResourceHttpRequestHandler |
getRequestHandler()
Returns a
ResourceHttpRequestHandler instance. |
protected List<ResourceResolver> |
getResourceResolvers() |
protected List<ResourceTransformer> |
getResourceTransformers() |
ResourceHandlerRegistration |
setCachePeriod(Integer cachePeriod)
Specify the cache period for the resources served by the resource handler, in seconds.
|
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)
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 addResolver(ResourceResolver resolver)
ResourceResolver
to the chain, allowing to resolve server-side resources from
HTTP requests.
ResourceResolver
s are registered, in the following order:
CachingResourceResolver
for caching the results of the next Resolvers; this resolver is only registered if you
did not provide your own instance of CachingResourceResolver
at the beginning of the chainResourceResolver
s registered using this method, in the order of methods callsVersionResourceResolver
if a versioning configuration has been applied with
addVersionStrategy
, addVersion
, etc.PathResourceResolver
for resolving resources on the file systemresolver
- a ResourceResolver
to add to the chain of resolversResourceHandlerRegistration
instance for chained method invocationResourceResolver
public ResourceHandlerRegistration addTransformer(ResourceTransformer transformer)
ResourceTransformer
to the chain, allowing to transform the content
of server-side resources when serving them to HTTP clients.
ResourceTransformer
s are registered, in the following order:
CachingResourceTransformer
for caching the results of the next Transformers; this transformer is only registered if you
did not provide your own instance of CachingResourceTransformer
at the beginning of the chainCssLinkResourceTransformer
for updating links within CSS files; this transformer
is only registered if a versioning configuration has been applied with addVersionStrategy
,
addVersion
, etcResourceTransformer
s registered using this method, in the order of methods callstransformer
- a ResourceTransformer
to add to the chain of transformersResourceHandlerRegistration
instance for chained method invocationResourceResolver
public ResourceHandlerRegistration addVersionStrategy(VersionStrategy strategy, String... pathPatterns)
VersionStrategy
. This is often used for cache busting.
Note that a CssLinkResourceTransformer
will be automatically registered to
support versioned resources in CSS files.
strategy
- the versioning strategy to usepathPatterns
- one or more resource URL path patternsResourceHandlerRegistration
instance for chained method invocationVersionResourceResolver
,
VersionStrategy
public ResourceHandlerRegistration addVersion(String fixedVersion, String... pathPatterns)
FixedVersionStrategy
.
This strategy uses that fixed version string and adds it as a prefix in the resource path,
e.g. fixedversion/js/main.js
.
There are many ways to get a version string for your application:
Note that a CssLinkResourceTransformer
will be automatically registered to
support versioned resources in CSS files.
fixedVersion
- a version stringpathPatterns
- one or more resource URL path patternsResourceHandlerRegistration
instance for chained method invocationVersionResourceResolver
,
FixedVersionStrategy
public ResourceHandlerRegistration addVersionHash(String... pathPatterns)
ContentVersionStrategy
.
This strategy uses the content of the Resource to create a String hash and adds it
in the resource filename, e.g. css/main-e36d2e05253c6c7085a91522ce43a0b4.css
.
Note that a CssLinkResourceTransformer
will be automatically registered to
support versioned resources in CSS files.
pathPatterns
- one or more resource URL path patternsResourceHandlerRegistration
instance for chained method invocationVersionResourceResolver
,
ContentVersionStrategy
public ResourceHandlerRegistration enableDevMode()
Resource
caching
if no caching Resolver/Transformer was manually registered.
Useful when updating static resources at runtime, i.e. during the development phase.
ResourceHandlerRegistration
instance for chained method invocationResourceResolver
,
ResourceTransformer
public ResourceHandlerRegistration setCachePeriod(Integer cachePeriod)
cachePeriod
- the time to cache resources in secondsResourceHandlerRegistration
instance for chained method invocationprotected String[] getPathPatterns()
protected List<ResourceResolver> getResourceResolvers()
protected List<ResourceTransformer> getResourceTransformers()
protected ResourceHttpRequestHandler getRequestHandler()
ResourceHttpRequestHandler
instance.