使用Neo4j嵌入式数据库和JDBC Bolt驱动程序进行Spring Boot测试 [英] Spring Boot Test using Neo4j embedded database with JDBC Bolt driver

查看:499
本文介绍了使用Neo4j嵌入式数据库和JDBC Bolt驱动程序进行Spring Boot测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像使用H2内存数据库模拟Oracle数据库一样连接到嵌入式Neo4j数据库?

Is it possible to connect to an embedded Neo4j database the same way you would do with an H2 in-memory database to mock an Oracle database?

我试图做到这一点:

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.datasource配置的JDBC Bolt驱动程序发出请求:

And then make a request using the JDBC Bolt driver with the following spring.datasource configuration:

spring:
  profiles: test
  datasource:
    driver-class-name: org.neo4j.jdbc.bolt.BoltDriver
    url: jdbc:neo4j:bolt://127.0.0.1:7688/?nossl

但是我总是收到以下错误:

But I always get the following error:

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数据库一样,连接到嵌入式数据库. 这是出于测试目的.

Of course the embedded database works when I use the graphDb instance and execute requests against it. But I want my application to connect to the embedded database as it does when connecting to a remote Neo4j database. This is for testing purpose.

推荐答案

我终于RTFM ...
我的pom.xml中有以下依赖项:

I finally RTFM...
I had the following dependency in my 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 该文档有些过时,因为它使用了已弃用的配置.但是他们对此进行了解释:

Then I found this: https://neo4j.com/docs/java-reference/current/tutorials-java-embedded/#tutorials-java-embedded-bolt The documentation is a bit outdated because it uses deprecated configuration. But they explain this:

Neo4j浏览器和官方Neo4j驱动程序使用Bolt数据库 与Neo4j通信的协议.默认情况下,Neo4j Embedded执行 不暴露Bolt连接器,但是您可以启用一个.这样做允许 您可以将服务Neo4j Browser连接到嵌入式实例.

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.

他们明确指出要使用的正确依赖项是:

And they make clear the correct dependency to use is:

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

这篇关于使用Neo4j嵌入式数据库和JDBC Bolt驱动程序进行Spring Boot测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆