Example usage for org.springframework.web.servlet.resource PathResourceResolver setUrlPathHelper

List of usage examples for org.springframework.web.servlet.resource PathResourceResolver setUrlPathHelper

Introduction

In this page you can find the example usage for org.springframework.web.servlet.resource PathResourceResolver setUrlPathHelper.

Prototype

public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) 

Source Link

Document

Provide a reference to the UrlPathHelper used to map requests to static resources.

Usage

From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java

/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this class.
 *//*from   ww w .  j av a2  s .  co  m*/
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
                pathResolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
            }
            if (this.urlPathHelper != null) {
                pathResolver.setLocationCharsets(this.locationCharsets);
                pathResolver.setUrlPathHelper(this.urlPathHelper);
            }
            break;
        }
    }
}