Skip to content
Advertisement

NoSuchBeanDefinitionException with reactive mongo repository: required a bean of type that could not be found

I have an issue: repository bean couldn’t be found when it’s placed in outer package. It causes nested UnsatisfiedDependencyException which is due to NoSuchBeanDefinitionException (expected at least 1 bean which qualifies as autowire candidate). After I copied the class to my project, it works perfectly. But I would like to use it as a dependency on external module. This is repository class:

JavaScript

And classes from project that should use the repository:

JavaScript

As you see, I have all needed annotations on beans (@Repository, @Service, @Configuration), I registered mongo repositories (@EnableMongoRepositories) and even provided the directory to scan (@ComponentScan). Do you have any ideas what I’ve missed?

UPD: I’m using maven and project structure is like this:

JavaScript

Advertisement

Answer

I’ve tried to reproduce the issue and it seems that changing the annotation

JavaScript

to its reactive equivalent:

JavaScript

solved the issue. More on that in the documentation

MongoDB uses two different drivers for imperative (synchronous/blocking) and reactive (non-blocking) data access. You must create a connection by using the Reactive Streams driver to provide the required infrastructure for Spring Data’s Reactive MongoDB support. Consequently, you must provide a separate configuration for MongoDB’s Reactive Streams driver. Note that your application operates on two different connections if you use reactive and blocking Spring Data MongoDB templates and repositories.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement