Springboot整合redis(Redisson、Jedis等)缓存项目启动故障,注解 缓存失效解决方案

启动故障ERROR

implementations of CachingConfigurer were found when only 1 was expected. Refactor the configuration such that CachingConfigurer is implemented only once or not at all.

public class RedissionConfig extends CachingConfigurerSupport {

springboot2.x默认使用lettuce
如:主动向容器添加Redisson时优先使用用户创建,
若用户放入容器的客户端实现CachingConfigurer接口,
与此同时配置类加上@EnableCaching,则为接口创建代理对象时出现多个实现类而抛出异常。

解决办法:二选一
亲测:实现接口方法使用@Cacheable等注解,缓存失效直接执行方法体。@EnableCaching方式能够正确执行

JedisConfig extends CachingConfigurerSupport

此时非容器中RedisConnectionFactory 的客户端实现CachingConfigurer接口,不会影响项目正常运行,缓存有效

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐