[英]@Cacheable Annotation gives 404
我必須實現Redis進行緩存管理。 我正在按照本教程進行操作,但是問題是當我在控制器方法上使用@Cacheable批注時,它為我提供了404狀態代碼。
我的控制器方法如下:
@GetMapping("auth/cache/{id}")
@Cacheable("test")
public ServiceResponse<String> checkingCache(@PathVariable("id") Integer id){
return new ServiceResponse<>(new String("String with id "+id));
}
當我刪除可緩存的注釋時,該方法將按預期工作。
我已經在機器上安裝了redis,它在默認端口上運行。 Redis的配置如下:
spring.cache.type=redis
spring.redis.host=localhost
spring.redis.port=6379
我有什么想念的嗎? 任何幫助將不勝感激,謝謝!
是否已使用教程中所述的注解@EnableCaching
啟用了緩存。
另外,由於需要緩存特定的ID,因此必須提供該密鑰以進行緩存。 您的示例應為:
@GetMapping("auth/cache/{id}")
@Cacheable(value = "test", key = "#id")
public ServiceResponse<String> checkingCache(@PathVariable("id") Integer id){
return new ServiceResponse<>(new String("String with id "+id));
}
如果沒有@PathVariable
,則可以@Cachable
沒有密鑰的情況下注釋@Cachable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.