代码之家  ›  专栏  ›  技术社区  ›  grandouassou

用Neo4j嵌入式数据库和JDBC驱动程序进行Spring引导测试

  •  0
  • grandouassou  · 技术社区  · 6 年前

    有没有可能像使用内存中的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();
    

    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 回复  |  直到 6 年前
        1
  •  1
  •   grandouassou    6 年前

    我终于。。。
    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 文档有点过时,因为它使用了不推荐使用的配置。但他们解释说:

    Neo4j浏览器和官方Neo4j驱动程序使用Bolt数据库 不暴露螺栓连接器,但可以启用一个。这样做允许 您需要将services Neo4j浏览器连接到嵌入式实例。

    他们明确指出正确的依赖关系是:

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-bolt</artifactId>
        <version>3.4.0</version>
    </dependency>