spring-boot-starter-data-redis 引发的一系列惨案

        
            org.springframework.boot
            spring-boot-starter-data-redis
        

pom 引入jar包 ,如果redis配置文件使用 lettuce ,还需要引入 commons-pool2 ,否则会报错


            org.apache.commons
            commons-pool2
        

还用到了redis分布式锁,引入

        
            
            org.springframework.boot
            spring-boot-starter-integration
            2.5.0
        
        
            
            org.springframework.integration
            spring-integration-redis
        

启动项目时,启动失败

有一条info信息

Multiple Spring Data modules found, entering strict repository configuration mode!

但是具体的错误信息是,有个 对象依赖关系无法解析的错误

开始怀疑是info信息里面的报错影响的

加了配置

  spring:
    data:
        redis:
          repositories:
            enabled: false

没用,再springboot启动类上加入

@SpringBootApplication(exclude = {RedisRepositoriesAutoConfiguration.class})

还是报一样的错误

搜索 RepositoryFactorySupport,的实现 

spring-boot-starter-data-redis 引发的一系列惨案_第1张图片

JpaRepositoryFactory,R2dbcRepositoryFactory,ReactiveRepositoryFactorySupport

是项目原有的,引入redis后出现 KeyValueRepositoryFactory,RedisRepositoryFactory

发现没法排除KeyValueRepositoryFactory ,暂时放弃这个info信息

解决对象依赖关系无法解析

No qualifying bean of type xxx available

核对了类的注解配置都没有问题

public interface xxxxx extends ReactiveSortingRepository {

....
}

怀疑应该是r2dbc 和 redis 之间存在冲突 ,ReactiveCrudRepository 是一个通用接口,可以分配给 Redis 和 R2DBC

最后将继承的repository类换成 R2dbcRepository

public interface xxxxx extends R2dbcRepository {

....
}

项目启动正常,后来校验了一下,原来的是这个对象里面使用的表已经不存在了。

你可能感兴趣的:(springboot,spring,redis,java)