2017-03-01 99 views
0

我有一個自動配置類SFConfig定義以下豆,因爲創建SalesforceClientConfig春天開機起動找不到豆

@Bean 
@ConditionalOnBean(value = SalesforceClientConfig.class) 
SalesforceClient sfClient(SalesforceClientConfig sfConfig){ 
    return SalesforceRestClient.from(sfConfig); 
} 

@Bean 
//@ConditionalOnBean(value = Authentication.class) 
SalesforceClientConfig sfClientConfig(Authentication sfAuthentication){ 
    return DefaultSalesforceClientConfig.builder() 
             .authentication(sfAuthentication) 
             .mapper(mapper()) 
             .build(); 
} 

可以明顯看出sfClient豆應創建。但它拋出一個異常:

Bean method 'sfClient' in 'SFConfig' not loaded because @ConditionalOnBean (types: com.ondeck.salesforceclient.SalesforceClientConfig; SearchStrategy: all) did not find any beans 

這很奇怪,因爲這是一個自動配置類,它應該找到該bean。有什麼想法嗎?

這裏是我如何在文件中定義我的自動配置類:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 

com.ondeck.letter.config.SpringJpaDBConfig,\ com.ondeck.letter.config.SFConfig

+0

我嘗試了一些東西,但它工作起來,但這是超級怪異的,我不能相信春天會做這樣的事情:我改變了類中的方法的順序,它的工作。這是正常的 –

回答

0

根據到Annotation Type ConditionalOnBean,建議在@EnableAutoConfiguration註釋的自動配置類中使用@ConditionalOnBean註釋。

所以可能你沒有正確定義自動配置類。

+0

我不認爲這是一個問題。當我切換其定義的方法的順序時,請參閱我的評論。 –

+0

是的,當您沒有正確的自動配置時,可能是Java編譯器的問題。 – hya

+0

我不確定什麼是適當的自動配置。我有spring.factories文件,並有配置文件。你介意闡述你的意思是「不適當」 –