在嵌入式Neo4j中使用Neo4j浏览器

本文介绍了如何在运行嵌入式Neo4j应用程序时使用Neo4j浏览器。通过WrappingNeoServerBootstrapper,可以在不干扰数据库进程的情况下访问Web浏览器。确保添加必要的Maven依赖,并按步骤启动服务。尽管该方法已弃用,但在 Neo4j 2.1.5 版本中仍有效,但未来版本的支持未得到保证。
摘要由CSDN通过智能技术生成

有时候,您有一个应用程序以嵌入式模式使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值