使用 spring-data-neo4j 时如何启用 neo4j webadmin?
How to enable neo4j webadmin when using spring-data-neo4j?
我正在从 Accessing Neo4j Data with REST 示例引导一个新项目。该示例使用嵌入式数据库而不是独立的 neo4j 服务器,但我想使用 Neo4J webadmin 界面来可视化我的数据。如何从这个配置开始启用 webadmin 界面?
(他们让 WrappingNeoServerBootstrapper 在 use WrappingNeoServerBootstrapper with spring-data-neo4j 中工作,但答案中省略了很多知识,例如,甚至没有提到配置的位置。作为 POM 的新手,Spring Boot 和 Neo4j 因此我不能使用那个答案。)
example you are using needs some tweaking to enable the Neo4j browser. I started from a different example, the Accessing Data with Neo4j 示例,效果很好。
您需要执行以下操作:
将 spring 启动 pom 上的版本更改为 1.2。1.Release:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
为 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 启动命令行 运行ner
public class Application extends Neo4jConfiguration implements CommandLineRunner{
在您的 Application.class:
中自动装配对 GraphDatabaseService 的引用
@Autowired
GraphDatabaseService db;
@在您的 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()
方法中配置的主机和端口上可用。
我正在从 Accessing Neo4j Data with REST 示例引导一个新项目。该示例使用嵌入式数据库而不是独立的 neo4j 服务器,但我想使用 Neo4J webadmin 界面来可视化我的数据。如何从这个配置开始启用 webadmin 界面?
(他们让 WrappingNeoServerBootstrapper 在 use WrappingNeoServerBootstrapper with spring-data-neo4j 中工作,但答案中省略了很多知识,例如,甚至没有提到配置的位置。作为 POM 的新手,Spring Boot 和 Neo4j 因此我不能使用那个答案。)
example you are using needs some tweaking to enable the Neo4j browser. I started from a different example, the Accessing Data with Neo4j 示例,效果很好。
您需要执行以下操作:
将 spring 启动 pom 上的版本更改为 1.2。1.Release:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.1.RELEASE</version> </parent>
为 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 启动命令行 运行nerpublic class Application extends Neo4jConfiguration implements CommandLineRunner{
在您的 Application.class:
中自动装配对 GraphDatabaseService 的引用@Autowired GraphDatabaseService db;
@在您的 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()
方法中配置的主机和端口上可用。