使用带有JDBC Bolt驱动程序的Neo4j嵌入式数据库进行java Spring启动测试
是否可以像使用内存中的H2数据库模拟Oracle数据库一样连接到嵌入式Neo4j数据库
我试着这么做:
final BoltConnector boltConnector = new BoltConnector("bolt");
graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(DB_PATH)
.setConfig(boltConnector.type, BOLT.name())
.setConfig(boltConnector.enabled, TRUE)
.setConfig(boltConnector.listen_address, listenAddress("127.0.0.1", 7688))
.setConfig(boltConnector.encryption_level, DISABLED.name())
.setConfig(GraphDatabaseSettings.auth_enabled, FALSE)
.newGraphDatabase();
然后使用JDBC Bolt驱动程序和下面的spring发出请求。数据源配置:
spring:
profiles: test
datasource:
driver-class-name: org.neo4j.jdbc.bolt.BoltDriver
url: jdbc:neo4j:bolt://127.0.0.1:7688/?nossl
但我总是会遇到以下错误:
Unable to connect to 127.0.0.1:7688, ensure the database is running and that there is a working network connection to it.
当然,当我使用graphDb
实例并对其执行请求时,嵌入式数据库就会工作。但我希望我的应用程序能像连接远程Neo4j数据库一样连接到嵌入式数据库。
这是为了测试目的
# 1 楼答案
我终于
我的
pom.xml
中有以下依赖项:然后我发现了这个:https://neo4j.com/docs/java-reference/current/tutorials-java-embedded/#tutorials-java-embedded-bolt 文档有点过时,因为它使用了不推荐的配置。但他们解释说:
他们明确指出,正确的依赖关系是: