我的春季MVC应用程序在localhost上运行良好。我有以下bean设置浏览器缓存:
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
// @formatter:off
registry.addResourceHandler("/doc/**").addResourceLocations("/WEB-INF/doc/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
registry.addResourceHandler("/style/**").addResourceLocations("/WEB-INF/style/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
registry.addResourceHandler("/image/**").addResourceLocations("/WEB-INF/image/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
registry.addResourceHandler("/javascript/**").addResourceLocations("/WEB-INF/javascript/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
registry.addResourceHandler("/plugin/**").addResourceLocations("/WEB-INF/plugin/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
registry.addResourceHandler("/**").addResourceLocations("/WEB-INF/root/").setCacheControl(DEFAULT_BROWSER_CACHE_CONTROL);
// @formatter:on
};
非常令人惊讶的是,当我将我的应用程序部署到服务器并在tomcat上发布时,浏览器缓存不起作用。对于exacy相同的图像,响应头如下
server:cache-control:no-cache,no-store,max-age = 0,must-revalidate
localhost:Cache-Control:max-age = 86400,public
这怎么可能?我在tomcat上没有任何特殊配置。