Different versioning strategies exist, and this resolver must be configured with one or more such strategies along with path mappings to indicate which strategy applies to which resources.
ContentVersionStrategy is a good default choice except in cases
where it cannot be used. Most notably the ContentVersionStrategy
cannot be combined with JavaScript module loaders. For such cases the
FixedVersionStrategy is a better choice.
Note that using this resolver to serve CSS files means that the
CssLinkResourceTransformer should also be used in order to modify
links within CSS files to also contain the appropriate versions generated
by this resolver.
VersionStrategy
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final AntPathMatcher | |
| private final Map | versionStrategyMap
Map from path pattern -> VersionStrategy. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public VersionResourceResolver | Returns: the current instance for chained method invocationone or more resource URL path patterns,
relative to the pattern configured with the resource handler pathPatterns)Insert a content-based version in resource URLs that match the given path patterns. |
| public VersionResourceResolver | Returns: the current instance for chained method invocationa version string version, String... one or more resource URL path patterns,
relative to the pattern configured with the resource handler pathPatterns)Insert a fixed, prefix-based version in resource URLs that match the given
path patterns, for example: |
| public VersionResourceResolver | Returns: the current instance for chained method invocationthe custom strategy strategy, String... one or more resource URL path patterns,
relative to the pattern configured with the resource handler pathPatterns)Register a custom VersionStrategy to apply to resource URLs that match the given path patterns. |
| protected VersionStrategy | Returns: an instance of aVersionStrategy or null if none matches that request pathFind a |
| public Map | |
| protected Resource | resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)
Implements abstract org.
|
| protected String | resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain)
Implements abstract org.
|
| public void | setStrategyMap(Map<String, VersionStrategy>
a map with URLs as keys and version strategies as values map)Set a Map with URL paths as keys and |
| pathMatcher | back to summary |
|---|---|
| private final AntPathMatcher pathMatcher | |
| versionStrategyMap | back to summary |
|---|---|
| private final Map<String, VersionStrategy> versionStrategyMap Map from path pattern -> VersionStrategy. | |
| VersionResourceResolver | back to summary |
|---|---|
| public VersionResourceResolver() | |
| addContentVersionStrategy | back to summary |
|---|---|
| public VersionResourceResolver addContentVersionStrategy(String... pathPatterns) Insert a content-based version in resource URLs that match the given path
patterns. The version is computed from the content of the file, e.g.
| |
| addFixedVersionStrategy | back to summary |
|---|---|
| public VersionResourceResolver addFixedVersionStrategy(String version, String... pathPatterns) Insert a fixed, prefix-based version in resource URLs that match the given
path patterns, for example: The version may be a random number, the current date, or a value
fetched from a git commit sha, a property file, or environment variable
and set with SpEL expressions in the configuration (e.g. see If not done already, variants of the given
| |
| addVersionStrategy | back to summary |
|---|---|
| public VersionResourceResolver addVersionStrategy(VersionStrategy strategy, String... pathPatterns) Register a custom VersionStrategy to apply to resource URLs that match the given path patterns.
| |
| getStrategyForPath | back to summary |
|---|---|
| protected VersionStrategy getStrategyForPath(String requestPath) Find a
| |
| getStrategyMap | back to summary |
|---|---|
| public Map Return the map with version strategies keyed by path pattern. | |
| resolveResourceInternal | back to summary |
|---|---|
| protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) Implements abstract org. | |
| resolveUrlPathInternal | back to summary |
|---|---|
| protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) Implements abstract org. | |
| setStrategyMap | back to summary |
|---|---|
| public void setStrategyMap(Map<String, VersionStrategy> map) Set a Map with URL paths as keys and Supports direct URL matches and Ant-style pattern matches. For syntax
details, see the
| |
| Access | Constructor and Description |
|---|---|
| public |
| original | back to summary |
|---|---|
| private final Resource original | |
| version | back to summary |
|---|---|
| private final String version | |
| FileNameVersionedResource | back to summary |
|---|---|
| public FileNameVersionedResource(Resource original, String version) | |
| contentLength | back to summary |
|---|---|
| public long contentLength() throws IOException Overrides org. Implements org. Doc from org. Determine the content length for this resource.
| |
| createRelative | back to summary |
|---|---|
| public Resource createRelative(String relativePath) throws IOException Overrides org. Implements org. Doc from org. Create a resource relative to this resource.
| |
| exists | back to summary |
|---|---|
| public boolean exists() Overrides org. Implements org. Doc from org. Determine whether this resource actually exists in physical form. This method performs a definitive existence check, whereas the
existence of a
| |
| getContentAsByteArray | back to summary |
|---|---|
| public byte[] getContentAsByteArray() throws IOException Overrides default org. Doc from org. Return the contents of this resource as a byte array.
| |
| getContentAsString | back to summary |
|---|---|
| public String getContentAsString(Charset charset) throws IOException Overrides default org. Doc from org. Return the contents of this resource as a string, using the specified charset.
| |
| getDescription | back to summary |
|---|---|
| public String getDescription() Implements org. Doc from org. Return a description for this resource, to be used for error output when working with the resource. Implementations are also encouraged to return this value
from their
| |
| getFile | back to summary |
|---|---|
| public File getFile() throws IOException Overrides org. Implements org. Doc from org. Return a File handle for this resource.
| |
| getFilename | back to summary |
|---|---|
| public String getFilename() Overrides org. Implements org. Doc from org. Determine the filename for this resource — typically the last
part of the path — for example, Returns Implementations are encouraged to return the filename unencoded. | |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Implements org. Doc from org. Return an It is expected that each call creates a fresh stream. This requirement is particularly important when you consider an API such
as JavaMail, which needs to be able to read the stream multiple times when
creating mail attachments. For such a use case, it is required
that each
| |
| getResponseHeaders | back to summary |
|---|---|
| public HttpHeaders getResponseHeaders() Implements org. Doc from org. The HTTP headers to be contributed to the HTTP response that serves the current resource.
| |
| getURI | back to summary |
|---|---|
| public URI getURI() throws IOException Overrides org. Implements org. Doc from org. Return a URI handle for this resource.
| |
| getURL | back to summary |
|---|---|
| public URL getURL() throws IOException Overrides org. Implements org. Doc from org. Return a URL handle for this resource.
| |
| isFile | back to summary |
|---|---|
| public boolean isFile() Overrides org. Overrides default org. Doc from org. Determine whether this resource represents a file in a file system. A value of This is conservatively
| |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Overrides org. Overrides default org. Doc from org. Indicate whether this resource represents a handle with an open stream.
If Will be
| |
| isReadable | back to summary |
|---|---|
| public boolean isReadable() Overrides org. Overrides default org. Doc from org. Indicate whether non-empty contents of this resource can be read via
Will be
| |
| lastModified | back to summary |
|---|---|
| public long lastModified() throws IOException Overrides org. Implements org. Doc from org. Determine the last-modified timestamp for this resource.
| |
| readableChannel | back to summary |
|---|---|
| public ReadableByteChannel readableChannel() throws IOException Overrides org. Overrides default org. Doc from org. Return a It is expected that each call creates a fresh channel. The default implementation returns
| |