Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何解决spring-data-neo4j与Grails 3.3.6之间的spring bean冲突_Spring Boot_Grails_Neo4j_Spring Data Neo4j_Neo4j Ogm - Fatal编程技术网

Spring boot 如何解决spring-data-neo4j与Grails 3.3.6之间的spring bean冲突

Spring boot 如何解决spring-data-neo4j与Grails 3.3.6之间的spring bean冲突,spring-boot,grails,neo4j,spring-data-neo4j,neo4j-ogm,Spring Boot,Grails,Neo4j,Spring Data Neo4j,Neo4j Ogm,我有一个Grails3.3.6应用程序。我想从另一个spring boot应用程序中合并此应用程序中的一些neo4j功能。因此,我从spring boot应用程序中添加了以下DEP- 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-

我有一个Grails3.3.6应用程序。我想从另一个spring boot应用程序中合并此应用程序中的一些neo4j功能。因此,我从spring boot应用程序中添加了以下DEP-

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'
并将源文件放在MyGrails应用程序的
src
文件夹中。spring boot应用程序正在使用一个配置类来创建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应用程序时,会出现springbean冲突异常。看起来Grails和neo4j正在尝试创建一些同名的bean-

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冲突?

您必须指定Neo4j会话工厂的bean名称。 在您的情况下,这应该按照您的预期工作:

@EnableNeo4jRepositories(sessionFactoryRef=“neo4jSessionFactory”,basePackages=“com.server.repositories”)

背景信息:SpringDataNeo4j将查找名为
sessionFactory
的bean。正如您在异常中所看到的,Hibernate也创建了一个具有这样一个名称的bean,并且它们发生冲突