我使用Spring Boot 1.0.2实现了一个REST服务器.我无法阻止Spring设置禁用HTTP缓存的HTTP标头.
我的控制器如下:
@Controller
public class MyRestController {
@RequestMapping(value = "/someUrl", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<String> myMethod(
HttpServletResponse httpResponse) throws SQLException {
return new ResponseEntity<String>("{}", HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
所有HTTP响应都包含以下标头:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: 0
Pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
我已尝试以下方法删除或更改这些标头:
setCacheSeconds(-1)控制器.httpResponse.setHeader("Cache-Control", "max-age=123")控制器.@Bean返回值.WebContentInterceptorsetCacheSeconds(-1)spring.resources.cache-period为-1或正值application.properties.以上都没有任何影响.如何在Spring Boot中为所有或单个请求禁用或更改这些标头?
在我的情况下,我有四种方法来解决我的问题:
index.html并禁用缓存(对我不起作用)index.html为index.jsp并禁用缓存,如下所示(对我有用,但我的客户组需要index.html)web.xml区分所需的请求并禁用缓存我的问题是如何使用 Spring Security 禁用缓存index.html
(也许使用intercept-urlinhttp标签)