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

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

(他们使用WrappingNeoServerBootstrapper使用带有spring-data-neo4j的WrappingNeoServerBootstrapper但是答案中省略了很多知识,例如它甚至没有提到配置的位置。作为POM的新手,Spring Boot和Neo4j因此我可以不要使用那个答案。)

您正在使用的示例需要进行一些调整才能启用Neo4j浏览器。 我从另一个例子开始, 使用Neo4j访问数据示例,它运行良好。

您需要执行以下操作:

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

     org.springframework.boot spring-boot-starter-parent 1.2.1.RELEASE  
  2. 为Neo4jServer添加依赖项:

      org.neo4j.app neo4j-server 2.1.5   org.neo4j.app neo4j-server 2.1.5 static-web  
  3. 在Application.class中实现Spring Boot命令行运行程序:

      public class Application extends Neo4jConfiguration implements CommandLineRunner{ 
  4. 在Application.class中自动添加对GraphDatabaseService的引用:

     @Autowired GraphDatabaseService db; 
  5. @Override Application.class中CommanLineRunner的run方法:

     @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()方法中配置的主机和端口上可用。