Example usage for org.springframework.web.servlet.resource ResourceHttpRequestHandler setLocations

List of usage examples for org.springframework.web.servlet.resource ResourceHttpRequestHandler setLocations

Introduction

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

Prototype

public void setLocations(List<Resource> locations) 

Source Link

Document

Set the List of Resource locations to use as sources for serving static resources.

Usage

From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHandlerRegistration.java

@Override
protected ResourceHttpRequestHandler getRequestHandler() {
    Field locationsField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "locations");
    ReflectionUtils.makeAccessible(locationsField);
    @SuppressWarnings("unchecked")
    List<Resource> locations = (List<Resource>) ReflectionUtils.getField(locationsField, this);

    Field cachePeriodField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "cachePeriod");
    ReflectionUtils.makeAccessible(cachePeriodField);
    Integer cachePeriod = (Integer) ReflectionUtils.getField(cachePeriodField, this);

    // Initial code is replace by a new Vfs2ResourceHttpRequestHandler()
    Assert.isTrue(!CollectionUtils.isEmpty(locations),
            "At least one location is required for resource handling.");
    ResourceHttpRequestHandler requestHandler = new Vfs2ResourceHttpRequestHandler();
    requestHandler.setLocations(locations);
    if (cachePeriod != null) {
        requestHandler.setCacheSeconds(cachePeriod);
    }//from  ww w  .ja v a2 s . c  om
    return requestHandler;
}