spring-framework / org.springframework.web.servlet.resource / PathResourceResolver

PathResourceResolver

open class PathResourceResolver : AbstractResourceResolver

A simple ResourceResolver that tries to find a resource under the given locations matching to the request path.

This resolver does not delegate to the ResourceResolverChain and is expected to be configured at the end in a chain of resolvers.

Author
Jeremy Grelle

Author
Rossen Stoyanchev

Author
Sam Brannen

Since
4.1

Constructors

<init>

PathResourceResolver()

A simple ResourceResolver that tries to find a resource under the given locations matching to the request path.

This resolver does not delegate to the ResourceResolverChain and is expected to be configured at the end in a chain of resolvers.

Functions

getAllowedLocations

open fun getAllowedLocations(): Array<Resource>

getLocationCharsets

open fun getLocationCharsets(): MutableMap<Resource, Charset>

Return charsets associated with static resource locations.

getUrlPathHelper

open fun getUrlPathHelper(): UrlPathHelper

The configured UrlPathHelper.

setAllowedLocations

open fun setAllowedLocations(vararg locations: Resource): Unit

By default when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found. However sometimes that may not be the case, e.g. when org.springframework.web.servlet.resource.CssLinkResourceTransformer resolves public URLs of links it contains, the CSS file is the location and the resources being resolved are css files, images, fonts and others located in adjacent or parent directories.

This property allows configuring a complete list of locations under which resources must be so that if a resource is not under the location relative to which it was found, this list may be checked as well.

By default ResourceHttpRequestHandler initializes this property to match its list of locations.

setLocationCharsets

open fun setLocationCharsets(locationCharsets: MutableMap<Resource, Charset>): Unit

Configure charsets associated with locations. If a static resource is found under a org.springframework.core.io.UrlResource location the charset is used to encode the relative path

Note: the charset is used only if the urlPathHelper property is also configured and its urlDecode property is set to true.

setUrlPathHelper

open fun setUrlPathHelper(urlPathHelper: UrlPathHelper): Unit

Provide a reference to the UrlPathHelper used to map requests to static resources. This helps to derive information about the lookup path such as whether it is decoded or not.