类 PathResourceResolver
- java.lang.Object
- org.springframework.web.servlet.resource.AbstractResourceResolver
- org.springframework.web.servlet.resource.PathResourceResolver
- 所有已实现的接口:
ResourceResolver
public class PathResourceResolver extends AbstractResourceResolver
A simpleResourceResolver
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.- 从以下版本开始:
- 4.1
- 作者:
- Jeremy Grelle, Rossen Stoyanchev, Sam Brannen
字段概要
从类继承的字段 org.springframework.web.servlet.resource.AbstractResourceResolver
logger
构造器概要
构造器 构造器 说明 PathResourceResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected boolean
checkResource(Resource resource, Resource location)
Perform additional checks on a resolved resource beyond checking whether the resources exists and is readable.Resource[]
getAllowedLocations()
Map<Resource,Charset>
getLocationCharsets()
Return charsets associated with static resource locations.protected Resource
getResource(String resourcePath, Resource location)
Find the resource under the given location.UrlPathHelper
getUrlPathHelper()
The configuredUrlPathHelper
.protected Resource
resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)
protected String
resolveUrlPathInternal(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain)
void
setAllowedLocations(Resource... locations)
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.void
setLocationCharsets(Map<Resource,Charset> locationCharsets)
Configure charsets associated with locations.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Provide a reference to theUrlPathHelper
used to map requests to static resources.从类继承的方法 org.springframework.web.servlet.resource.AbstractResourceResolver
resolveResource, resolveUrlPath
构造器详细资料
PathResourceResolver
public PathResourceResolver()
方法详细资料
setAllowedLocations
public void setAllowedLocations(Resource... locations)
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. whenCssLinkResourceTransformer
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.- 参数:
locations
- the list of allowed locations- 从以下版本开始:
- 4.1.2
- 另请参阅:
ResourceHttpRequestHandler.initAllowedLocations()
getAllowedLocations
public Resource[] getAllowedLocations()
setLocationCharsets
public void setLocationCharsets(Map<Resource,Charset> locationCharsets)
Configure charsets associated with locations. If a static resource is found under aURL resource
location the charset is used to encode the relative pathNote: the charset is used only if the
urlPathHelper
property is also configured and itsurlDecode
property is set to true.- 从以下版本开始:
- 4.3.13
getLocationCharsets
public Map<Resource,Charset> getLocationCharsets()
Return charsets associated with static resource locations.- 从以下版本开始:
- 4.3.13
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Provide a reference to theUrlPathHelper
used to map requests to static resources. This helps to derive information about the lookup path such as whether it is decoded or not.- 从以下版本开始:
- 4.3.13
getUrlPathHelper
public UrlPathHelper getUrlPathHelper()
The configuredUrlPathHelper
.- 从以下版本开始:
- 4.3.13
resolveResourceInternal
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)
resolveUrlPathInternal
protected String resolveUrlPathInternal(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain)
getResource
protected Resource getResource(String resourcePath, Resource location) throws IOException
Find the resource under the given location.The default implementation checks if there is a readable
Resource
for the given path relative to the location.- 参数:
resourcePath
- the path to the resourcelocation
- the location to check- 返回:
- the resource, or
null
if none found - 抛出:
IOException
checkResource
protected boolean checkResource(Resource resource, Resource location) throws IOException
Perform additional checks on a resolved resource beyond checking whether the resources exists and is readable. The default implementation also verifies the resource is either under the location relative to which it was found or is under one of theallowed locations
.- 参数:
resource
- the resource to checklocation
- the location relative to which the resource was found- 返回:
- "true" if resource is in a valid location, "false" otherwise.
- 抛出:
IOException
- 从以下版本开始:
- 4.1.2