【发布时间】:2018-10-15 06:47:22
【问题描述】:
我有一个基本的 SpringBoot 2.0.5.RELEASE 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR
我已经创建了这个 Rest 方法:
@GetMapping(path = "/users/notifications", consumes = "application/json", produces = "application/json")
public ResponseEntity<List<UserNotification>> userNotifications(
@RequestHeader(value = "Authorization") String authHeader) {
User user = authUserOnPath("/users/notifications", authHeader);
List<UserNotification> menuAlertNotifications = menuService
.getLast365DaysNotificationsByUser(user);
return ResponseEntity.ok(menuAlertNotifications)
.cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS));;
}
我想添加一个缓存控制标头,但我不知道如何... 我得到一个编译错误:
Multiple markers at this line
- The method cacheControl(CacheControl) is undefined for the type
ResponseEntity<List<UserNotification>>
- CacheControl
- cacheControl
我也在application.properties中添加了这个属性
security.headers.cache=false
【问题讨论】:
-
你在使用spring security吗?
-
是的,我正在使用 Spring Security
标签: java rest spring-boot http-headers resttemplate