我有一个Grails 3.3.6应用程序。我想将这个应用程序中的一些neo4j功能从不同的春季引导应用程序中合并。所以我从spring引导应用程序中添加了以下程序-
compile "org.neo4j:neo4j:3.1.0"
compile "org.neo4j.driver:neo4j-java-driver:1.1.0"
compile "org.neo4j:neo4j-ogm-core:2.1.6"
compile "org.neo4j:neo4j-ogm-http-driver:2.1.6"
runtime "org.neo4j:neo4j-ogm-embedded-driver:2.1.6"
runtime "org.neo4j:neo4j-ogm-bolt-driver:2.1.6"
compile "org.springframework.boot:spring-boot-starter-data-neo4j"
compile 'org.springframework.data:spring-data-neo4j:4.2.0.RELEASE'并将源文件放在我的Grails应用程序的src文件夹中。spring引导应用程序使用配置类来创建bean,如下所示-
Configuration
@EnableNeo4jRepositories("com.server.repositories")
public class TestConfiguration {
@Value("${spring.data.neo4j.uri}")
String neo4jURL;
@Value("${spring.data.neo4j.username}")
String neo4jUser;
@Value("${spring.data.neo4j.password}")
String neo4jPass;
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
return new org.neo4j.ogm.config.Configuration.Builder().credentials(neo4jUser, neo4jPass).uri(neo4jURL).build();
}
@Bean
public SessionFactory neo4jSessionFactory() {
// with domain entity base package(s)
return new SessionFactory(configuration(), "com.server.model");
}
@Bean
public Neo4jTransactionManager neo4jTransactionManager() {
return new Neo4jTransactionManager(neo4jSessionFactory());
}
@Bean
public Session neo4jSession() {
return neo4jTransactionManager().getSessionFactory().openSession();
}当我运行grails应用程序时,我会得到spring冲突异常。看来Grails和neo4j正在尝试创建一些同名的beans
Unsatisfied dependency expressed through field 'neo4jSession'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.data.neo4j.transaction.SharedSessionCreator#0': Unsatisfied dependency expressed through method 'createSharedSession' parameter 0: Could not convert argument value of type [org.hibernate.internal.SessionFactoryImpl] to required type [org.neo4j.ogm.session.SessionFactory]: Failed to convert value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.neo4j.ogm.session.SessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.neo4j.ogm.session.SessionFactory': no matching editors or conversion strategy found我应该如何解决这些bean冲突?
发布于 2018-07-04 08:15:28
您必须指定Neo4j会话工厂的bean名称。在您的情况下,这应该如您所期望的那样工作:
@EnableNeo4jRepositories(sessionFactoryRef = "neo4jSessionFactory", basePackages = "com.server.repositories")
背景信息: Spring Neo4j将查找名为sessionFactory的bean。正如您在异常中所看到的,Hibernate还创建了一个具有这样一个名称的bean,并且它们会发生冲突。
https://stackoverflow.com/questions/51041093
复制相似问题