Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Spring'配置缓存时出现问题;s ResourceHandlerRegistry_Spring_Spring Mvc_Caching_Browser Cache_Cache Control - Fatal编程技术网

使用Spring'配置缓存时出现问题;s ResourceHandlerRegistry

使用Spring'配置缓存时出现问题;s ResourceHandlerRegistry,spring,spring-mvc,caching,browser-cache,cache-control,Spring,Spring Mvc,Caching,Browser Cache,Cache Control,我正在尝试使用Spring的ResourceHandlerRegistry为单页应用程序配置缓存控制 我需要将index.html页面不缓存,并将所有其他类路径资源(已升级的CSS和JS)缓存 以下是我的想法: @Configuration @Profile(Profiles.CLOUD) class CloudWebMvcConfiguration extends WebMvcConfigurerAdapter { private static final int ONE_YEAR

我正在尝试使用Spring的
ResourceHandlerRegistry
为单页应用程序配置缓存控制

我需要将
index.html
页面不缓存,并将所有其他类路径资源(已升级的CSS和JS)缓存

以下是我的想法:

@Configuration
@Profile(Profiles.CLOUD)
class CloudWebMvcConfiguration extends WebMvcConfigurerAdapter {

    private static final int ONE_YEAR = 365 * 24 * 60 * 60;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")//
                .addResourceLocations("classpath:/")//
                .setCachePeriod(ONE_YEAR);
        registry.addResourceHandler("/")//
                .addResourceLocations("classpath:/index.html")//
                .setCachePeriod(0);
    }
}
但是,在chrome控制台中查看响应标题表明
index.html
页面也被缓存:

Remote Address:[::1]:5000
Request URL:http://localhost:5000/
Request Method:GET
Status Code:304 Not Modified
Response Headers
view source
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Date:Wed, 26 Aug 2015 20:09:14 GMT
Expires:0
Last-Modified:Wed, 26 Aug 2015 19:58:27 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Application-Context:application:cloud:5000
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
请参见未修改的
304

以下是我如何提供
index.html
(它映射到
/
):

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/index.html");
    }