0

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?

I've tried to do this:

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();

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.

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.

1 Answer 1

1

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>

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:

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.