如何在同一个 spring 启动应用程序中配置 neo4j 和 cassandra 存储库
How to configure neo4j and cassandra repositories in same spring boot application
我已经使用 spring-data 分别配置了 neo4j 和 cassandra 存储库 spring 引导。但是,当我尝试在同一个项目中使用两个存储库时,它无法按预期工作。
这是我的文件夹结构。
-----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-data 存储库。
当我 运行 使用此配置时,会出现以下错误。
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 启动?
这看起来 Spring 引导自动配置无法同时处理多个 Spring 数据项目。
Spring Data Neo4j and 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
我已经使用 spring-data 分别配置了 neo4j 和 cassandra 存储库 spring 引导。但是,当我尝试在同一个项目中使用两个存储库时,它无法按预期工作。
这是我的文件夹结构。
-----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-data 存储库。
当我 运行 使用此配置时,会出现以下错误。
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 启动?
这看起来 Spring 引导自动配置无法同时处理多个 Spring 数据项目。
Spring Data Neo4j and 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