【问题标题】:How to configure Neo4j embedded driver specified in ogm.properties?如何配置 ogm.properties 中指定的 Neo4j 嵌入式驱动程序?
【发布时间】:2017-09-26 17:49:38
【问题描述】:
我的 Java 程序在特定于应用程序的$DATA_DIR 中查找ogm.properties 并加载一个Configuration,它用于构造SessionFactory。默认ogm.properties 使用嵌入式驱动程序和指向$DATA_DIR 子目录的文件URI。到目前为止一切顺利。
这个想法是用户可以提供他们自己的ogm.properties 使用不同的驱动程序。因此,我不能将自定义的GraphDatabaseService 传递给EmbeddedDriver 构造函数,因为我自己没有构造它。
如何将configuration options 传递给嵌入式驱动程序?我尝试在$DATA_DIR 下的不同位置放置neo4j.conf,但似乎无法识别。
【问题讨论】:
标签:
java
neo4j-ogm
neo4j-embedded
【解决方案1】:
在 2018 年底即将推出的 Neo4j 3.1.6 中,您将能够执行以下操作:
在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
或在 Java 配置中以编程方式:
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();
将配置文件从文件或类路径资源传递到嵌入式实例。