spring cache: Cannot find cache named xxxx

1,459 阅读1分钟

发生情景

今日又来改造瑞吉外卖了,但是前几天还正常运行的程序突然报错:

Cannot find cache named 'categoryCache' for Builder[public com.example.demo.common.Result com.example.demo.controller.CategoryController.showCategoryList(int,int)] caches=[categoryCache] | key=''categoryPage_'+#page+'_'+#pageSize' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false

image.png

解决策略

在application.yml中添加cache-namestype,cache-names的值为 @Cacheable(value="categoryList",key="'categoryList_'+#category.getType()" ) 中value的内容

cache-names:
  - categoryList
  - categoryCache
type: simple

image.png