Java 如何在SpringDataNeo4J4.2.x自定义存储库中注入会话?
我正在从spring-data-neo4j版本4.1迁移到4.2。 在应用程序启动时,我收到一个错误:Java 如何在SpringDataNeo4J4.2.x自定义存储库中注入会话?,java,spring,neo4j,spring-data-neo4j,Java,Spring,Neo4j,Spring Data Neo4j,我正在从spring-data-neo4j版本4.1迁移到4.2。 在应用程序启动时,我收到一个错误: 通过构造函数参数0表示的未满足依赖关系;嵌套异常为org.springframework.beans.factory.NoSuchBean定义异常:没有类型为“org.neo4j.ogm.session.session”的合格bean可用:至少需要1个符合autowire候选条件的bean。依赖项批注:{} repository.ActivityRecordRepository.java:
通过构造函数参数0表示的未满足依赖关系;嵌套异常为org.springframework.beans.factory.NoSuchBean定义异常:没有类型为“org.neo4j.ogm.session.session”的合格bean可用:至少需要1个符合autowire候选条件的bean。依赖项批注:{}
repository.ActivityRecordRepository.java:
public interface ActivityRecordRepository extends GraphRepository<ActivityRecord>, ActivityRecordRepositoryCustom {}
repository.impl.ActivityRecordRepositoryImpl.java:
public class ActivityRecordRepositoryImpl implements ActivityRecordRepositoryCustom {
private final Session session;
public ActivityRecordRepositoryImpl(Session session) {
this.session = session;
}
....
}
我的配置:
@ComponentScan
@Configuration
@EnableNeo4jRepositories("com.example.repository")
@EnableTransactionManagement
public class ApplicationConfiguration {
....
@Bean
public EventListener eventListener() {
return new CustomEventListener();
}
@Bean
public SessionFactory getSessionFactory() {
final SessionFactory sessionFactory = new SessionFactory(databaseConfiguration, "com.example.entity");
sessionFactory.register(eventListener());
return sessionFactory;
}
}
如何正确地将会话对象自动连接到自定义存储库实现
我正在使用:
Spring版本:4.3.2.发布Spring Data Neo4j版本:4.2.11.发布版自动连接
会话工厂而不是会话工厂
是否有效?@meistermeier否然后失败,出现此异常:工厂方法“getSessionFactory”引发异常;嵌套的异常是java.lang.NoSuchMethodError:org.neo4j.ogm.session.SessionFactory.register(Lorg/neo4j/ogm/session/event/EventListener;)
@Slava对不起,我的5美分,但我只是想知道,既然SDN 5.x已经存在,为什么您需要迁移到SDN4.2?@alexanoid,因为SDN 5.x需要spring版本5+。我的项目使用Spring4,我认为这是一个符合您正在寻找的Neo4J和spring版本的示例。
@ComponentScan
@Configuration
@EnableNeo4jRepositories("com.example.repository")
@EnableTransactionManagement
public class ApplicationConfiguration {
....
@Bean
public EventListener eventListener() {
return new CustomEventListener();
}
@Bean
public SessionFactory getSessionFactory() {
final SessionFactory sessionFactory = new SessionFactory(databaseConfiguration, "com.example.entity");
sessionFactory.register(eventListener());
return sessionFactory;
}
}