如何在同一个Spring启动应用程序中配置neo4j和cassandra存储库 [英] How to configure neo4j and cassandra repositories in same spring boot application

查看:625
本文介绍了如何在同一个Spring启动应用程序中配置neo4j和cassandra存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have configured neo4j and cassandra repositories separately with spring boot using spring-data. However, when I try to use two repositories in the same projects it doesn't work as expected.

这是我的文件夹结构。

----- org.test.project

-----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。

Note that all the repositories extend respective spring-datarepository with respective DAO.

当我运行这个时配置它会出现以下错误。

When I run with this configurations it gives the following error.

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

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

I tried changing the Repository names. Then it started to work.

第一个问题是我们不能拥有与不同包装中相同的名称并开始工作

虽然这次开始工作但它在认证标题中出错。

Though it started to work this time it gave an error in the authentication header.

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

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

I have already added ogm.properties, the same way I did when I was using neo4j repositories only. But it seems they no longer get applied. So I added following into 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

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

With the above changes, now it is giving following error.

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

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

Note that a neo4j.ogm exception is thrown for the cassandra models. What is happening under the hood. How can I configure these two databases with spring boot in one project as above?

推荐答案

这看起来像Spring Boot一样,autoconfiguration无法同时处理多个Spring Data项目。

This looks like the Spring Boot autoconfiguration is not able to handle multiple Spring Data projects at the same time.

请参阅 Spring Data Neo4j Spring Data Cassandra

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

In particular you should point SDN module to neo4j repositories only

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

和cassandra类似。

and similarly for cassandra.

这篇关于如何在同一个Spring启动应用程序中配置neo4j和cassandra存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆