How to configure Neo4j embedded driver specified in ogm.properties?

167 Views Asked by At

My Java program looks for ogm.properties in an application-specific $DATA_DIR and loads a Configuration that it uses to construct a SessionFactory. The default ogm.properties uses the embedded driver and a file URI that points to a subdirectory of $DATA_DIR. So far so good.

The idea is that the user could supply their own ogm.properties that uses a different driver. Therefore, I can't pass a custom GraphDatabaseService to the EmbeddedDriver constructor because I don't construct it myself.

How can I pass configuration options to the embedded driver? I tried placing a neo4j.conf in various locations under $DATA_DIR, but it didn't seem to be recognized.

1

There are 1 best solutions below

0
On

In Neo4j 3.1.6 upcoming by the end of 2018 you'll be able to do the following:

In ogm.properties:

# Looks in the root of the classpath
neo4j.conf.location=neo4j.conf

# Explicitly in the classpath
# neo4j.conf.location=classpath:neo4j.conf

# Or as file URL
# neo4j.conf.location=file:///config/neo4j.conf

Or programmatically in Java configuration:

String neo4jConfLocation;

​// Choose one:
​// Looks in the root of the classpath
neo4jConfLocation = "neo4j.conf"

​// Explicitly in the classpath
​// neo4jConfLocation = "classpath:neo4j.conf"

​// Or as file URL
​// neo4jConfLocation = "file:///config/neo4j.conf"

Configuration configuration =
    new Configuration.Builder()
        .neo4jConfLocation(neo4jConfLocation)
        .build();

To pass a configuration file from file or classpath resource to the embedded instance.