使用J2CACHE的时候出现one as primary or declare a specific CacheManager to use

       以前我们直接使用的是RedisCacheManager作为缓存,但是当时是没有考虑性能方面的问题,比如网络延迟从缓存中取数据,如果能首先从本地缓存取到数据这样就最好了,没有网络延迟的开销,如果不能本地缓存获取到数据,然后在去从Redis中获取数据,然后存入到本地缓存中,这样就可以最大化的提高性能,因此把Redis作为直接缓存修改为了开源中国的j2cache作为缓存架构,因为刚开始的时候一不小心就造就了如下异常

java.lang.IllegalStateException: No CacheResolver specified, and no unique bean of type CacheManager found. Mark one as primary or declare a specific CacheManager to use.
	at org.springframework.cache.interceptor.CacheAspectSupport.afterSingletonsInstantiated(CacheAspectSupport.java:223) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:67) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at com.yaya.product.ProductApp.main(ProductApp.java:21) [classes/:na]

       一看到这个错误,我靠,什么鬼,跟踪代码进行居然发现了真的是2个cache bean,分别是redisCacheManager和cacheManager,刚开始的时候半天没有想明白啊,在网上也没有人说出现过这个问题,自己单独建一个空项目来引用也没有出现这个问题,看来是代码的问题了,反正是没有想起自己手动创建过RedisCacheManager这个bean对象,跟踪代码发现Redis自己好像也实现了RedisCacheManager啊,还一直以为是框架的问题,经过慢慢的仔细观察,这个才想起来原来是自己的锅啊,简直浪费时间,所以如果前面代码中使用过RedisCacheManager作为缓存的在转换为j2cache作为缓存的时候一定要记得注释掉或者删除了RedisCacheManager bean,不然简直是瞎忙活,当然如果要替换为其他的缓存框架也一样要记得,最后贴一下j2cache的地址https://gitee.com/ld/J2Cache/tree/master

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值