neo4j 嵌入式
有时,您有一个应用程序以嵌入式模式使用Neo4j,但还需要使用Neo4j Web浏览器来处理图形。 由于一次最多只能从一个进程访问数据库,因此在嵌入式Neo4j应用程序运行时尝试启动Neo4j服务器将不起作用。
WrappingNeoServerBootstrapper虽然已被弃用,但可以进行救援。
设置方法如下。
1.确保您具有这些Maven依赖项
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>2.1.5</version>
<classifier>static-web</classifier>
</dependency>
2.启动WrappingNeoServerBootstrapper
public static void connectAndStartBootstrapper() {
WrappingNeoServerBootstrapper neoServerBootstrapper;
GraphDatabaseService db = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder("/path/to/db").newGraphDatabase();
registerShutdownHook(db);
try {
GraphDatabaseAPI api = (GraphDatabaseAPI) db;
ServerConfigurator config = new ServerConfigurator(api);
config.configuration()
.addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
config.configuration()
.addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "7575");
neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
neoServerBootstrapper.start();
catch(Exception e) {
//handle appropriately
}
}
这里发生两件事-GraphDatabaseService准备在嵌入式模式下使用,Neo4j Web浏览器可用于http://127.0.0.1:7575/
您无需一起启动它们,而是根据需要启动和停止WrappingNeoServerBootstrapper,您只需要拥有GraphDatabaseService的句柄。
再次注意,不建议使用WrappingNeoServerBootstrapper。 在编写本文时,此代码适用于2.1.5,但不能为Neo4j的将来版本提供任何保证。
翻译自: https://www.javacodegeeks.com/2014/11/using-the-neo4j-browser-with-embedded-neo4j.html
neo4j 嵌入式