I have this spring boot project (version 2.3.3.RELEASE) that uses Spring Webflux and Spring Data and R2DBC. It was working fine until I added the following dependency:
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
After this, Spring can't start because it can't resolve the dependency for this object:
interface BookingCountRepository : ReactiveCrudRepository<BookingCount, String> {
...
}
The error message is the following:
2021-12-22 10:20:59,916 [main] ERROR [] o.s.b.d.LoggingFailureAnalysisReporter - __***************************_APPLICATION FAILED TO START_***************************__Description:__Parameter 1 of constructor in xx.xx.xx.xx.BookingService required a bean of type 'xx.xx.xx.xx.BookingCountRepository' that could not be found.___Action:__Consider defining a bean of type 'xx.xx.xx.xx.BookingCountRepository' in your configuration._
If I remove the spring-boot-starter-data-redis dependency, the problem stops happening.
My hunch is that it's probably a dependency hell issue, with a conflict between org.springframework.boot:spring-boot-starter-data-r2dbc and org.springframework.boot:spring-boot-starter-data-redis. But I don't know for sure.
Did anyone have trouble with this? If you did, how did you solve this problem?
FYI: JVM Runtime is OpenJDK 11, language is Kotlin, and spring boot version is 2.3.3.RELEASE
I was able to find a solution, therefore I'm posting here, since others may face the same problem.
The cause of the problem is that multiple spring data modules (r2dbc and redis) were being used in the same project. Since ReactiveCrudRepository is a generic interface that can be assigned to both Redis and R2DBC, something must be done to ensure Spring DI loads the correct spring data modules.
The solution, in this case, is making BookingCountRepository inherit directly from R2dbcRepository:
interface BookingCountRepository : R2dbcRepository<BookingCount, String> {
...
}
After that, everything will work correctly.
More information in the docs:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.multiple-modules
Note: Some approaches, like informing basePackages in the @EnableR2dbcRepositories annotations didn't work.