如何在同一个Spring启动应用程序中配置neo4j和cassandra存储库

我使用spring-data分别使用spring boot配置了neo4j和cassandra存储库。 但是,当我尝试在同一个项目中使用两个存储库时,它无法按预期工作。

这是我的文件夹结构。

—– org.test.project

-----controller BarController FooController -----models -----dao -----cassandra BarDAO FooDAO -----neo4j BarDAO FooDAO -----repositories -----cassandra BarRepository FooRepository -----neo BarRepository FooRepository -----services CassandraService (Has cassandra repositories @Autowired) NeoService(Has neo repositories @Autowired) TestApp.java 

请注意,所有存储库都使用相应的DAO扩展相应的spring-datarepository。

当我使用此配置运行时,它会出现以下错误。

  Field airportRepository in org.test.project.TestApp required a bean of type 'org.test.project.repositories.cassandra.BarRepository' that could not be found. 

我尝试更改存储库名称。 然后它开始工作。

第一个问题是,我们不能在不同的包装中使用相同的名称并开始工作

虽然这次开始工作但它在身份validation标头中出错了。

  org.neo4j.ogm.drivers.http.request.HttpRequestException: http://localhost:7474/db/data/transaction/commit: No authentication header supplied. 

我已经添加了ogm.properties,就像我在使用neo4j存储库时所做的那样。 但它似乎不再适用。 所以我在application.properties中添加了以下内容。

  spring.data.neo4j.password=neo4j spring.data.neo4j.username=neo4j 

第二个问题是,我如何配置neo4j就像我只使用neo4j一样? 我在ogm.properties中定义了以下内容。 如何将其应用于neo4j配置?

  #Driver, required driver=org.neo4j.ogm.drivers.bolt.driver.BoltDriver #URI of the Neo4j database, required. If no port is specified, the #default port 7687 is used. Otherwise, a port can be specified with #bolt://neo4j:password@localhost:1234 URI=bolt://neo4j:neo4j@localhost #Connection pool size (the maximum number of sessions per URL), #optional, defaults to 50 connection.pool.size=150 #Encryption level (TLS), optional, defaults to REQUIRED. Valid #values are NONE,REQUIRED encryption.level=NONE 

通过上述更改,现在出现以下错误。

  org.neo4j.ogm.exception.MappingException: No identity field found for class: org.rozzie.processor.models.dao.cassandra.FlightDAO 

请注意,cassandra模型会抛出neo4j.ogmexception。 引擎盖下发生了什么。 如何在上面的一个项目中使用spring boot配置这两个数据库?

这看起来像Spring Boot自动配置无法同时处理多个Spring Data项目。

请参阅Spring Data Neo4j和Spring Data Cassandra的文档

特别是您应该将SDN模块指向neo4j存储库

 @EnableNeo4jRepositories(basePackages = "org.test.project.repositories.neo") 

和cassandra一样。

我用过mongo的neo4j。 我没有看到任何问题。 我认为它应该与cassandra相同。 这是我的所有配置

 @SpringBootApplication @EnableConfigurationProperties @EnableNeo4jRepositories("com.in.neo4j.repository.neo") @EnableMongoRepositories("com.in.neo4j.repository.mongo") public class Neo4JApplication { public static void main(String[] args) { SpringApplication.run(Neo4JApplication.class, args); } } 

在我的属性文件中,我有

 spring.data.neo4j.username=neo4j spring.data.neo4j.password=admin spring.data.mongodb.database=blah spring.data.mongodb.host=blahblah spring.data.mongodb.port=27017