相关疑难解决方法(0)

如何在Spring Boot中启用HTTP响应缓存

我使用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)

我已尝试以下方法删除或更改这些标头:

  1. 呼叫setCacheSeconds(-1)控制器.
  2. 呼叫httpResponse.setHeader("Cache-Control", "max-age=123")控制器.
  3. 定义我调用的@Bean返回值.WebContentInterceptorsetCacheSeconds(-1)
  4. 将属性设置spring.resources.cache-period为-1或正值application.properties.

以上都没有任何影响.如何在Spring Boot中为所有或单个请求禁用或更改这些标头?

java spring spring-mvc spring-security spring-boot

47
推荐指数
4
解决办法
6万
查看次数

在 spring security 中禁用特定 url 的缓存

在我的情况下,我有四种方法来解决我的问题:

  1. 在我的中写入元配置index.html并禁用缓存(对我不起作用)
  2. 更改index.htmlindex.jsp并禁用缓存,如下所示(对我有用,但我的客户组需要index.html)
  3. 使用过滤器web.xml区分所需的请求并禁用缓存
  4. 春季安全

我的问题是如何使用 Spring Security 禁用缓存index.html (也许使用intercept-urlinhttp标签)

java cache-control spring-security

1
推荐指数
1
解决办法
7776
查看次数