Spring Boot + Neo4j 获取GraphDatabaseService bean?
Spring Boot + Neo4j get GraphDatabaseService bean?
使用新式 (Spring Data Neo4j 4.1.2.RELEASE) Neo4jConfiguration 我可以获取对底层嵌入式 GraphDatabaseService 的引用以传递到网络 ui?
新样式配置:
@Configuration
@EnableNeo4jRepositories(basePackages = "fu.bar")
@EnableTransactionManagement
public class Neo4j extends Neo4jConfiguration {
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
.setURI("file:///var/tmp/graph.db");
return config;
}
@Bean
public SessionFactory getSessionFactory() {
SessionFactory sessionFactory = new SessionFactory(getConfiguration(), "fu.bar");
return sessionFactory;
}
我在 Javadoc 中没有看到任何有用的信息,但我怀疑 Boot 在某个地方有一个实例。
谢谢。
如果您使用的是嵌入式驱动程序,GraphDatabaseService
可以通过以下方式获得:
EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
使用 HTTP,可以通过以下方式直接访问数据库:
String uri = Components.driver().getConfiguration().getURI() +
"/db/data/index/node/" + indexName;
HttpPost httpPost = new HttpPost(uri);
这些示例来自 Spring Data Neo4j 参考指南的 section on indexes。
使用新式 (Spring Data Neo4j 4.1.2.RELEASE) Neo4jConfiguration 我可以获取对底层嵌入式 GraphDatabaseService 的引用以传递到网络 ui?
新样式配置:
@Configuration
@EnableNeo4jRepositories(basePackages = "fu.bar")
@EnableTransactionManagement
public class Neo4j extends Neo4jConfiguration {
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
.setURI("file:///var/tmp/graph.db");
return config;
}
@Bean
public SessionFactory getSessionFactory() {
SessionFactory sessionFactory = new SessionFactory(getConfiguration(), "fu.bar");
return sessionFactory;
}
我在 Javadoc 中没有看到任何有用的信息,但我怀疑 Boot 在某个地方有一个实例。
谢谢。
如果您使用的是嵌入式驱动程序,GraphDatabaseService
可以通过以下方式获得:
EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
使用 HTTP,可以通过以下方式直接访问数据库:
String uri = Components.driver().getConfiguration().getURI() +
"/db/data/index/node/" + indexName;
HttpPost httpPost = new HttpPost(uri);
这些示例来自 Spring Data Neo4j 参考指南的 section on indexes。