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

标签 java spring maven neo4j spring-data-neo4j

我正在从 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/

相关文章:

java - MQJE001 : Completion Code '2' , 原因 '2538'

java - CAS 身份验证 SAML 错误

WildFly 上的 javax.naming.NameNotFoundException EJB HelloWorld

java - 是否可以根据springboot中application.properties中的前缀创建多个bean

spring - 如何在 RestController 中缓存 InputStreamResource?

java - 在 GUI 中使用不同的布局

java - 如何使用 Spring MVC 对上传的文件数量设置最大限制?

java - 在 Jenkins 上升级到 JDK11 后 Maven 编译器错误(线程问题?)

java - 有没有 Javadoc 拼写检查器?

android - 我如何告诉 gradle 使用最新的库、快照或不使用?