簡體   English   中英

如何在使用spring-data-neo4j時啟用neo4j webadmin?

[英]How to enable neo4j webadmin when using spring-data-neo4j?

我正在使用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。請:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM