gpt4 book ai didi

java - 使用spring-data-neo4j时如何启用neo4j webadmin?

转载 作者:行者123 更新时间:2023-11-29 05:12:30 25 4
gpt4 key购买 nike

我正在从 Accessing Neo4j Data with REST 启动一个新项目例子。该示例使用嵌入式数据库而不是独立的 neo4j 服务器,但我想使用 Neo4J webadmin 界面来可视化我的数据。如何从这个配置开始启用 webadmin 界面?

(他们让 WrappingNeoServerBootstrapper 在 use WrappingNeoServerBootstrapper with spring-data-neo4j 工作,但答案中省略了很多知识,例如,甚至没有提到配置的位置。作为 POM、Spring Boot 和 Neo4j 的新手,我因此不能利用那个答案。)

最佳答案

example您正在使用需要一些调整来启用 Neo4j 浏览器。我从一个不同的例子开始,Accessing Data with Neo4j示例,效果很好。

您需要执行以下操作:

  1. 将 spring boot pom 上的版本更改为 1.2.1.Release:

     <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.1.RELEASE</version>
    </parent>
  2. 为 Neo4jServer 添加依赖项:

    <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>
  3. 在您的 Application.class 中实现 Spring Boot 命令行运行器:

     public class Application extends Neo4jConfiguration implements CommandLineRunner{
  4. 在您的 Application.class 中 Autowiring 对 GraphDatabaseService 的引用:

    @Autowired
    GraphDatabaseService db;
  5. @在您的 Application.class 中重写 CommanLineRunner 的运行方法:

    @Override
    public void run(String... strings) throws Exception {
    // used for Neo4j browser
    try {
    WrappingNeoServerBootstrapper neoServerBootstrapper;
    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, "8686");

    neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
    neoServerBootstrapper.start();
    } catch(Exception e) {
    //handle appropriately
    }
    // end of Neo4j browser config
    }

完成后,您的 Application.class 应该如下所示:

package hello;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;

@Configuration
@EnableNeo4jRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application extends Neo4jConfiguration implements CommandLineRunner{

public Application() {
setBasePackage("hello");
}

@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabase("target/hello.db");
}

@Autowired
GraphDatabaseService db;



@Override
public void run(String... strings) throws Exception {
// used for Neo4j browser
try {
WrappingNeoServerBootstrapper neoServerBootstrapper;
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, "8686");

neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
neoServerBootstrapper.start();
} catch(Exception e) {
//handle appropriately
}
// end of Neo4j browser config
}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}


}

Neo4j 浏览器将在您的 run() 方法中配置的主机和端口上可用。

关于java - 使用spring-data-neo4j时如何启用neo4j webadmin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27883424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com