HttpRequestHandler that serves static resources in an optimized way
according to the guidelines of Page Speed, YSlow, etc.
The "locations" property takes a list of Spring
Resource locations from which static resources are allowed to be served
by this handler. Resources could be served from a classpath location, e.g.
"classpath:/META-INF/public-web-resources/", allowing convenient packaging
and serving of resources such as .js, .css, and others in jar files.
This request handler may also be configured with a
resourceTransformer chains to support
arbitrary resolution and transformation of resources being served. By default
a PathResourceResolver simply finds resources based on the configured
"locations". An application can configure additional resolvers and transformers
such as the VersionResourceResolver which can resolve and prepare URLs
for resources with a version in the URL.
This handler also properly evaluates the Last-Modified header
(if present) so that a 304 status code will be returned as appropriate,
avoiding unnecessary overhead for resources that are already cached by the client.
Keith Donald, Jeremy Grelle, Juergen Hoeller, Arjen Poutsma, Brian Clozel, Rossen Stoyanchev
public void setLocationValues(java.util.List<java.lang.String> locationValues)
An alternative to setLocations(List) that accepts a list of
String-based location values, with support for UrlResource's
(e.g. files or HTTP URLs) with a special prefix to indicate the charset
to use when appending relative paths. For example
public void setLocations(java.util.List<Resource> locations)
Set the List of Resource locations to use as sources
for serving static resources.
Checks for the existence of the requested resource in the configured list of locations.
If the resource does not exist, a 404 response will be returned to the client.
If the resource exists, the request will be checked for the presence of the
Last-Modified header, and its value will be compared against the last-modified
timestamp of the given resource, returning a 304 status code if the
Last-Modified value is greater. If the resource is newer than the
Last-Modified value, or the header is not present, the content resource
of the resource will be written to the response with caching headers
set to expire one year in the future.