类 PathResourceResolver

  • 所有已实现的接口:
    ResourceResolver

    public class PathResourceResolver
    extends 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.

    从以下版本开始:
    5.0
    作者:
    Rossen Stoyanchev
    • 方法详细资料

      • setAllowedLocations

        public void setAllowedLocations​(@Nullable
                                        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. when 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 ResourceWebHandler initializes this property to match its list of locations.

        参数:
        locations - the list of allowed locations
      • getResource

        protected reactor.core.publisher.Mono<ResourcegetResource​(String resourcePath,
                                                                    Resource location)
        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 resource
        location - the location to check
        返回:
        the resource, or empty Mono if none found
      • 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 the allowed locations.
        参数:
        resource - the resource to check
        location - the location relative to which the resource was found
        返回:
        "true" if resource is in a valid location, "false" otherwise.
        抛出:
        IOException