使用spring-data-neo4j时如何启用neo4j webadmin? [英] How to enable neo4j webadmin when using spring-data-neo4j?
问题描述
我正在从 使用 REST 访问 Neo4j 数据 示例.该示例使用嵌入式数据库而不是独立的 neo4j 服务器,但我想使用 Neo4J webadmin 界面来可视化我的数据.如何从此配置开始启用 webadmin 界面?
I am bootstrapping a new project from the Accessing Neo4j Data with REST example. The example uses an embedded database rather than a standalone neo4j server, but I would like to use the Neo4J webadmin interface for visualisation of my data. How do I enable the webadmin interface starting from this configuration?
(他们让 WrappingNeoServerBootstrapper 在使用 WrappingNeoServerBootstrapper 和 spring-data-neo4j 但是答案中省略了很多知识,例如甚至没有提到将配置放在何处.作为 POM、Spring Boot 和 Neo4j 的新手,我因此无法使用该答案.)
(They got WrappingNeoServerBootstrapper working in use WrappingNeoServerBootstrapper with spring-data-neo4j but a lot of knowledge is omitted from the answer, e.g. it is not even mentioned where to place to the configuration. Being new to POMs, Spring Boot and Neo4j I therefore can't make use of that answer.)
推荐答案
example 您正在使用需要一些调整以启用 Neo4j 浏览器.我从一个不同的例子开始,Accessing Data with Neo4j 示例,效果很好.
The example you are using needs some tweaking to enable the Neo4j browser. I started from a different example, the Accessing Data with Neo4j example and it worked well.
您需要执行以下操作:
将 spring boot pom 上的版本更改为 1.2.1.Release:
Change the version on your spring boot pom to 1.2.1.Release:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
为 Neo4jServer 添加依赖项:
Add dependencies for 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>
在您的 Application.class 中实现 Spring Boot 命令行运行程序:
Implement the Spring Boot command line runner in your Application.class:
public class Application extends Neo4jConfiguration implements CommandLineRunner{
在 Application.class 中自动连接对 GraphDatabaseService 的引用:
Autowire a reference to your GraphDatabaseService in your Application.class:
@Autowired
GraphDatabaseService db;
@Override 在您的 Application.class 中来自 CommanLineRunner 的 run 方法:
@Override the run method from CommanLineRunner in your Application.class:
@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 应如下所示:
When you are all done, your Application.class should look like this:
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()
方法中配置的主机和端口上可用.
The Neo4j browser will be available on the host and port configured in your run()
method.
这篇关于使用spring-data-neo4j时如何启用neo4j webadmin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!