如何设置在春季启动时禁用浏览器缓存?

时间:2019-02-18 05:57:17

标签: spring spring-boot caching browser-cache

我想在春季启动时设置禁用浏览器缓存(缓存控制:无缓存,无存储,最大年龄= 0)。

我的环境

  spring-boot: 2.1.2
  spring-security: not use

我搜索是否要设置响应标头的缓存控件:无缓存, 只需在“ application.yml”处添加即可。

像这样

spring.resources.cache:
  cachecontrol:
    max-age: 0
    no-cache: true
    no-store: true
    cache-private: true

spring.resources.chain.cache: false

但是它不起作用。

我无法在chrome浏览器的响应标头中显示缓存控制标头。

在弹簧框架中,我刚刚设置

<mvc:mapping path="/**"/>
    <bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
         <property name="cacheSeconds" value="0"/>
         <property name="useExpiresHeader" value="true"/>
         <property name="useCacheControlHeader" value="true"/>
         <property name="useCacheControlNoStore" value="true"/>
    </bean>
</mvc:interceptor>

如何在没有Spring安全性的情况下在Spring Boot中设置禁用浏览器缓存?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试通过在application.properties中添加此行

spring.cache.type=NONE