2016-11-28 109 views
0

我遇到了Spring引導1.4.2.M1和@EnableExperimentalNeo4jRepositories的問題。NoUniqueBeanDefinitionException用@EnableExperimentalNeo4jRepositories註釋和SpringBoot 1.4.2

這似乎是兩個豆,一個春季啓動,一個spring-data-neo4j之間的衝突。

這裏是一個堆棧跟蹤摘錄:

18:12:15.891 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception 
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.neo4j.ogm.session.Session' available: expected single matching bean but found 2: getSession,org.springframework.data.neo4j.transaction.SharedSessionCreator#0 

而另一...

Parameter 0 of method setSession in org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryBean required a single bean, but 2 were found: 
    - getSession: defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration$SpringBootNeo4jConfiguration.class] 
    - org.springframework.data.neo4j.transaction.SharedSessionCreator#0: defined by method 'createSharedSession' in null 

任何人有任何想法如何解決這個問題?

下面是我的Neo4j配置

package com.domain.core.context; 

import javax.annotation.PostConstruct; 

import org.neo4j.ogm.session.Session; 
import org.neo4j.ogm.session.SessionFactory; 
import org.neo4j.ogm.session.event.Event; 
import org.neo4j.ogm.session.event.EventListenerAdapter; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.neo4j.repository.config.EnableExperimentalNeo4jRepositories; 
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager; 
import org.springframework.transaction.annotation.EnableTransactionManagement; 

import lombok.extern.slf4j.Slf4j; 

@Slf4j 
@Configuration 
@ComponentScan("com.domain") 
@EnableExperimentalNeo4jRepositories(basePackages = "com.domain.core.repository") 
@EnableTransactionManagement 
@SpringBootApplication(exclude = Neo4jDataAutoConfiguration.class) 
public class TestPersistenceContext { 

    @PostConstruct 
    public void init() { 
     log.info("TheScene.Co: Initializing Test Neo4jConfig ..."); 
    } 

    @Bean 
    public Neo4jTransactionManager transactionManager() throws Exception { 
     return new Neo4jTransactionManager(sessionFactory()); 
    } 

    @Bean 
    public SessionFactory sessionFactory() { 
     return new SessionFactory(getConfiguration(), "com.domain") { 

      @Override 
      public Session openSession() { 
       Session session = super.openSession(); 
       session.register(new EventListenerAdapter() { 
        @Override 
        public void onPreSave(Event event) { 
         // do something - like set an id on an object 
         log.debug("***** Saving domain object ********"); 
        } 
       }); 

       return session; 
      } 
     }; 
    } 


    @Bean 
    public org.neo4j.ogm.config.Configuration getConfiguration() { 
     org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); 
     config.driverConfiguration().setCredentials("neo4j", "password") 
       .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver"); 

     return config; 
    } 

} 

回答

1

您必須使用4.2.0.M1春數據的Neo4j(SDN)的版本。這個里程碑版本已經發布,可以獲得關於4.1.x的幾個重大更改的反饋。

SDN 4.2.0.RC1應該是出在本週晚些時候但現在4.2.0.BUILD-SNAPSHOT實際上是在含鉛量高達爲Decemeber春數據Ingalls發佈列車相當穩定。

I have written a guide針對來自SDN 4.0/4.1的用戶,它介紹瞭如何升級到快照構建。

在本指南there is a link中的一個示例項目分支,它展示瞭如何使這個版本與Spring Boot 1.4.x一起工作,並有一些小的工作。

通過即將發佈的Spring Boot 1.5,我們更新了所有自動配置,以便SDN 4.2開箱即用。我們會將Spring Boot的文檔更新版本更近一些。