2017-04-26 46 views
1

我有一個使用spring-kafka的Spring引導項目。在這個項目中,我已經構建了一些包裝spring-kafka bean的事件驅動組件(即KafkaTemplate和ConcurrentKafkaListenerContainer)。我想讓這個項目成爲一個可重用的庫,可以跨越一系列Spring引導應用程序。但是,當我從春天啓動應用程序添加依賴於這個庫我在應用程序啓動時出現錯誤:春季引導:排除一些自動配置的豆

APPLICATION FAILED TO START 


Description: 

Parameter 1 of method kafkaListenerContainerFactory in org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration required a bean of type 'org.springframework.kafka.core.ConsumerFactory' that could not be found. 
    - Bean method 'kafkaConsumerFactory' in 'KafkaAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.kafka.core.ConsumerFactory; SearchStrategy: all) found bean 'kafkaConsumerFactory' 


Action: 

Consider revisiting the conditions above or defining a bean of type 'org.springframework.kafka.core.ConsumerFactory' in your configuration. 

因爲我需要自動裝配一個ConsumerFactory<A, B>(而不是ConsumerFactory<Object, Object>)我在配置類中創建這個bean這與@EnableConfigurationProperties(KafkaProperties.class)

註釋的所有我需要的是不重複使用其他豆類org.springframework.boot.autoconfigure.kafka.KafkaProperties在KafkaAutoConfiguration和KafkaAnnotationDrivenConfiguration被自動配置。

我試圖把@EnableAutoConfiguration(排除= KafkaAutoConfiguration.class)在我的圖書館,但這沒有阻止這取決於我的圖書館觸發彈簧卡夫​​卡自動配置排除在圖書館的應用。

我怎麼可以指定我不希望在我的圖書館一些豆類(KafkaAutoConfiguration和KafkaAnnotationDrivenConfiguration)的自動配置,但也依賴於該庫任何應用程序?

回答

1

我相信依賴庫的應用程序本身必須將這些類從它們的自動配置中排除。