有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用带有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) 个答案

  1. # 1 楼答案

    我终于
    我的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>