为什么@Cacheable注释导致java.lang.IllegalArgumentException?

为什么@Cacheable注释导致java.lang.IllegalArgumentException?,java,spring,rest,caching,Java,Spring,Rest,Caching,我刚刚在@RestController中的methode中添加了@Cacheable(value=“testCaching”,key=“#id”),如下所示: @Cacheable(value = "testCaching", key = "#id") public Book getCachedMsg(@PathVariable("id") final int id, final HttpServletResponse response) 并得到以下错误: java.lang.Ille

我刚刚在
@RestController
中的methode中添加了
@Cacheable(value=“testCaching”,key=“#id”)
,如下所示:

  @Cacheable(value = "testCaching", key = "#id")
  public Book getCachedMsg(@PathVariable("id") final int id, final HttpServletResponse response)
并得到以下错误:

java.lang.IllegalArgumentException: Name for argument type [int] not available, and parameter name information not found in class file either.
有人知道原因吗?

试试这个:

  @Cacheable(value = "testCaching", key = "#p0")
  public Book getCachedMsg(@PathVariable("id") final int id, final HttpServletResponse response)

您是否尝试过使用“key=id”?您的意思是删除;是的,我也犯了同样的错误!问题可能是因为您正在向控制器方法添加可缓存注释,如果从控制器调用某个服务并在其中包含可缓存注释,可能会更好。你能试试吗?是的,我这样做了,但没有得到错误,但缓存不起作用:(我的项目中有可缓存的,但没有键,只有名称,因为它是一个getAllXX(),让我检查可能是什么问题。但试着使用第二种方法,在服务中的可缓存方法,而不是在控制器中