Search code examples
spring-bootspring-data-mongodbspring-data-neo4j-4

Using spring-data-mongodb and spring-data-neo4j together


How can I use spring-data-mongodb and spring-data-neo4j in the same spring-boot application?

I can easily use one or the other following the "getting started" guides, but as soon as I try to add Neo4J to a MongoDB application then I get runtime errors such as:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type MongoBook!

I've setup a minimal example at https://github.com/afaulconbridge/myspring-mongo-neo


Solution

  • As @manish pointed out, you need to make Spring Data MongoDB and Spring Data Neo4J scan separate packages. i.e.

    @EnableMongoRepositories(basePackageClasses=MongoBook.class)
    @EnableNeo4jRepositories(basePackageClasses=NeoAuthor.class)
    

    I've updated the example project at https://github.com/afaulconbridge/myspring-mongo-neo with a solution.