是否可以像使用 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.datasource 配置发出请求:
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 数据库一样连接到嵌入式数据库。
这是出于测试目的。
最佳答案
我终于 RTFM...
我的 pom.xml
中有以下依赖项:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.4.0</version>
</dependency>
然后我发现了这个:https://neo4j.com/docs/java-reference/current/tutorials-java-embedded/#tutorials-java-embedded-bolt 该文档有点过时,因为它使用了已弃用的配置。但他们解释了这一点:
The Neo4j Browser and the official Neo4j Drivers use the Bolt database protocol to communicate with Neo4j. By default, Neo4j Embedded does not expose a Bolt connector, but you can enable one. Doing so allows you to connect the services Neo4j Browser to your embedded instance.
他们明确指出要使用的正确依赖项是:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-bolt</artifactId>
<version>3.4.0</version>
</dependency>
关于java - 使用带有 JDBC Bolt 驱动程序的 Neo4j 嵌入式数据库进行 Spring Boot 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52132826/