java - 来自 RestController 的 Spring Boot 响应中没有缓存标头
问题描述
我有一个返回 JSON 的典型控制器,我需要返回no-cache
标头作为响应的一部分。请注意,此时我在类路径上没有弹簧安全性,但是如果需要让它开箱即用,那么我可以接受这个。
目前我已经通过以下方式实现了这一点:
public static <T> ResponseEntity<T> createResponseSpringWay(final T body) {
org.springframework.http.CacheControl cacheControl = org.springframework.http.CacheControl.noCache();
return ResponseEntity.ok().cacheControl(cacheControl).body(body);
}
是否有任何弹簧引导属性可以为我自动生成?我想摆脱ResponseEntity
所有方法。
我尝试了以下配置,但我相信它只适用于静态资源,所以它不起作用:
spring.resources.cache.cachecontrol.no-store=true
spring.resources.cache.cachecontrol.must-revalidate=true
spring.resources.cache.cachecontrol.no-cache=true
解决方案
推荐阅读
- javascript - 如何使用 jQuery 定位按钮以从特定文本区域获取文本?
- python - exec() 中的 Python 函数未添加到 globals/locals dict
- javascript - 相同类型的对象永远不能被认为是“相同的”但相同类型的原语可以被认为是重要的吗?
- c++ - 为什么 ^z 有两个 ASCII 码?
- apache-spark - Pyspark 数据帧写入和读取更改架构
- arrays - 如何在 Swift 5 中从数组中获取值
- python - 对位置历史中具有相同地址的位置进行分组,同时保持位置顺序
- java - java - 如何在没有中间提交的情况下查看两个提交之间的更改?
- c++ - 将数组元素中的双精度值返回到控制台
- .net - 我创建了一个接受命令行参数/拖放的 VB.NET 表单应用程序。我如何让它与控制台对话?