gpt4 book ai didi

java - 如何在同一个 Spring Boot 应用程序中配置 Neo4j 和 cassandra 存储库

转载 作者:行者123 更新时间:2023-11-30 02:32:08 25 4
gpt4 key购买 nike

我已经使用 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.

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

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

虽然这次开始工作,但它在身份验证 header 中出现错误。

 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.ogm 异常。幕后发生了什么。 如何在一个项目中使用 spring boot 配置这两个数据库,如上所述?

最佳答案

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

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

特别是,您应该仅将 SDN 模块指向 Neo4j 存储库

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

对于 cassandra 来说也是如此。

关于java - 如何在同一个 Spring Boot 应用程序中配置 Neo4j 和 cassandra 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44033599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com