spring-framework / org.springframework.web.servlet.config.annotation / ResourceHandlerRegistration

ResourceHandlerRegistration

open class ResourceHandlerRegistration

Encapsulates information required to create a resource handler.

Author
Rossen Stoyanchev

Author
Keith Donald

Author
Brian Clozel

Since
3.1

Constructors

<init>

ResourceHandlerRegistration(vararg pathPatterns: String)

Create a ResourceHandlerRegistration instance.

Functions

addResourceLocations

open fun addResourceLocations(vararg resourceLocations: String): ResourceHandlerRegistration

Add one or more resource locations from which to serve static content. 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.

For org.springframework.core.io.UrlResource (e.g. files, HTTP URLs, etc) this method supports a special prefix to indicate the charset associated with the URL so that relative paths appended to it can be encoded correctly, e.g. [charset=Windows-31J]http://example.org/path.

resourceChain

open fun resourceChain(cacheResources: Boolean): ResourceChainRegistration
open fun resourceChain(cacheResources: Boolean, cache: Cache): ResourceChainRegistration

Configure a chain of resource resolvers and transformers to use. This can be useful, for example, to apply a version strategy to resource URLs.

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.

setCacheControl

open fun setCacheControl(cacheControl: CacheControl): ResourceHandlerRegistration

Specify the org.springframework.http.CacheControl which should be used by the resource handler.

Setting a custom value here will override the configuration set with #setCachePeriod.

setCachePeriod

open fun setCachePeriod(cachePeriod: Int): ResourceHandlerRegistration

Specify the cache period for the resources served by the resource handler, in seconds. The default is to not send any cache headers but to rely on last-modified timestamps only. Set to 0 in order to send cache headers that prevent caching, or to a positive number of seconds to send cache headers with the given max-age value.