Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 设置筛选器bean时插入的重复缓存控制标头_Spring_Spring Boot_Spring Cache - Fatal编程技术网

Spring 设置筛选器bean时插入的重复缓存控制标头

Spring 设置筛选器bean时插入的重复缓存控制标头,spring,spring-boot,spring-cache,Spring,Spring Boot,Spring Cache,我设置了一个过滤器bean来插入和重置缓存控制头。这工作正常,除了在过滤器后面的一小点,额外的缓存控制头被插入 我正在使用弹簧靴。 有没有解决问题的办法 @Component public class CacheControlFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException {} @Override

我设置了一个过滤器bean来插入和重置
缓存控制
头。这工作正常,除了在过滤器后面的一小点,额外的
缓存控制
头被插入

我正在使用
弹簧靴
。 有没有解决问题的办法

@Component
public class CacheControlFilter implements Filter {

     @Override
     public void init(FilterConfig filterConfig) throws ServletException {}

     @Override
     public void destroy() {}

     @Override
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
        Calendar expires = Calendar.getInstance();
        expires.add(Calendar.HOUR, 24);

        // Intercept response header
        HttpServletResponse resp = (HttpServletResponse) response;
        resp.setDateHeader("Expires", expires.getTimeInMillis());
        resp.setHeader("Cache-Control", "max-age=2048");
        chain.doFilter(request, resp);
     }
}
请参阅重复的
缓存控件
标题:

HTTP/1.1 200 OK  
...  
Cache-Control: max-age=2048  
Cache-Control: no-cache, no-store, max-age=0, must-revalidate  
Expires: Fri, 26 Sep 2014 18:21:30 GMT  
Expires: 0  
Pragma: no-cache  
Content-Type: image/png  
...  

你在使用Spring安全性吗

Spring security也将自动添加它们,您可以在配置中禁用它们,如下所示:

class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override protected void configure(HttpSecurity http) throws Exception {
        //... Rest of config

        http.headers().disable()
详情请参见此处:


您还可以根据需要将特定标头配置为打开/关闭(请参阅该API文档中的其他方法,例如
cacheControl()
etc)

IDE中是否具有调试功能?如果您将日志记录改为跟踪,并在正在调用的筛选器中添加一些断点,那么您应该能够找到添加断点的位置(假设您确信在其他地方没有应用程序代码设置标题),还可以向我们显示安全配置吗?是否只有一个安全配置文件?FOI-还应删除application.properties文件中的
spring.resources.cache period
属性,以禁止
spring boot
添加其默认缓存控制头。