【问题标题】:Using spring-data-mongodb and spring-data-neo4j together一起使用 spring-data-mongodb 和 spring-data-neo4j
【发布时间】:2016-12-19 15:45:19
【问题描述】:

如何在同一个 spring-boot 应用程序中使用 spring-data-mongodb 和 spring-data-neo4j?

我可以按照“入门”指南轻松使用其中一种,但是一旦我尝试将 Neo4J 添加到 MongoDB 应用程序中,就会出现运行时错误,例如:

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!

我在https://github.com/afaulconbridge/myspring-mongo-neo 设置了一个最小示例

【问题讨论】:

标签: spring-boot spring-data-mongodb spring-data-neo4j-4


【解决方案1】:

你可以try this project 一起使用 JPA 和 Neo4J。该结构在技术上也应该适用于 Mongo。请注意,Mongo 不支持事务的概念,因此您可能不必为每个 Spring Data 项目定义显式事务管理器。

【讨论】:

    【解决方案2】:

    正如@manish 指出的,您需要让 Spring Data MongoDB 和 Spring Data Neo4J 扫描单独的包。即

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

    我已经用解决方案更新了https://github.com/afaulconbridge/myspring-mongo-neo 的示例项目。

    【讨论】:

      【解决方案3】:

      即使在同一个包中,您也应该能够分别使用excludeFiltersincludeFilters 参数(大多数情况下includeFilters 就足够了)

      @EnableMongoRepositories(basePackageClasses=MongoBook.class,
        includeFilters ={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
        classes = {MongoRepository.class}))
      
      @EnableNeo4jRepositories(basePackageClasses=NeoAuthor.class,
        includeFilters ={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, 
        classes = {NeoRepository.class}))
      

      来自includeFilters()的描述

      指定哪些类型适合组件扫描。更远 将候选组件集从 {#basePackages()} 中的所有内容缩小到与给定过滤器匹配的基本包中的所有内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-02
        • 2014-10-21
        • 1970-01-01
        • 2017-10-11
        • 1970-01-01
        • 1970-01-01
        • 2012-06-01
        相关资源
        最近更新 更多