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

本文介绍了如何在运行嵌入式Neo4j应用程序时,通过WrappingNeoServerBootstrapper启动Neo4j浏览器。尽管WrappingNeoServerBootstrapper已弃用,但在2.1.5版本中,它仍可用于让图形数据库在http://127.0.0.1:7575/上可用,同时保持GraphDatabaseService的嵌入式使用。只需确保拥有正确的Maven依赖,并按需启动和停止该服务。
摘要由CSDN通过智能技术生成

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 嵌入式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值