Spring Data Neo4j 示例 -- 如何将其应用到 Spring Data Neo4j v4.1
Spring Data Neo4j example -- how to adopt it to Spring Data Neo4j v4.1
我正在努力如何转换此示例:https://spring.io/guides/gs/accessing-data-neo4j/ 以处理新版本的 Spring 数据。我显然将 Person.java 的导入更改为 org.neo4j.ogm.*。我添加了:
@Bean
public SessionFactory getSessionFactory()
{
logger.info("ApplicationConfig::getSessionFactory()");
return new SessionFactory("hello");
}
@Bean
public Session getSession() throws Exception {
logger.info("Initialising Neo4jSession");
SessionFactory sessionFactory = getSessionFactory();
Assert.notNull(sessionFactory, "You must provide a SessionFactory instance in your Spring configuration classes");
return sessionFactory.openSession();
}
到Application.java文件。
但是我不知道怎么改方法:
@Bean CommandLineRunner demo(PersonRepository personRepository,
GraphDatabase graphDatabase)
上班。我已经尝试将代码从这个方法移动到其 class 的构造函数,但我需要有 PersonRepository.
不应使用 GraphDatabaseService 来管理事务,如果您注入 org.neo4j.ogm.session.Session
,您将使用
session.beginTransaction()
据我所知,PersonRepository 将像在 SDN 3 中一样被注入。
这里还有两篇介绍SDN 4.1的文章-
http://graphaware.com/neo4j/2015/12/15/the-essence-of-spring-data-neo4j-4.html
http://graphaware.com/neo4j/2016/02/24/upgrading-spring-data-neo4j-4-1.html
我正在努力如何转换此示例:https://spring.io/guides/gs/accessing-data-neo4j/ 以处理新版本的 Spring 数据。我显然将 Person.java 的导入更改为 org.neo4j.ogm.*。我添加了:
@Bean
public SessionFactory getSessionFactory()
{
logger.info("ApplicationConfig::getSessionFactory()");
return new SessionFactory("hello");
}
@Bean
public Session getSession() throws Exception {
logger.info("Initialising Neo4jSession");
SessionFactory sessionFactory = getSessionFactory();
Assert.notNull(sessionFactory, "You must provide a SessionFactory instance in your Spring configuration classes");
return sessionFactory.openSession();
}
到Application.java文件。 但是我不知道怎么改方法:
@Bean CommandLineRunner demo(PersonRepository personRepository, GraphDatabase graphDatabase)
上班。我已经尝试将代码从这个方法移动到其 class 的构造函数,但我需要有 PersonRepository.
不应使用 GraphDatabaseService 来管理事务,如果您注入 org.neo4j.ogm.session.Session
,您将使用
session.beginTransaction()
据我所知,PersonRepository 将像在 SDN 3 中一样被注入。
这里还有两篇介绍SDN 4.1的文章-
http://graphaware.com/neo4j/2015/12/15/the-essence-of-spring-data-neo4j-4.html http://graphaware.com/neo4j/2016/02/24/upgrading-spring-data-neo4j-4-1.html