2016-07-27 42 views
1

在讀取stackoverflow上的answers對之後。我試圖執行它的建議方式,但我仍然沒有得到我的component中的字符串列表。將application.yml中的字符串列表加載到組件中

這裏是我的application.yml文件

appName: 
    db: 
    host: localhost 
    username: userX 
    password: passX 
    driverClassName: org.postgresql.Driver 
    shipment: 
    providers: 
     supported1: 
     - one 
     - two 

而且我component類是

@Component 
@ConfigurationProperties(prefix = "appName.shipment.providers") 
public class ProviderUtil { 
    List<String> supported1; 

    /* This class has other util methods as well */ 
} 

在這裏,我期待的是supported1將有串onetwo的列表中,但它是空的。有人能幫助這裏發生的事情以及如何解決它嗎?

回答

1

你的類路徑是否具有spring-boot-configuration-processor依賴性? 儘量顯得here

而且還從@Component改變你的bean @Configuration

+0

是啊,我有整整增加它它在文檔中提到的方法。與'可選'值設置爲'真正',我用'組件'因爲這個響應>> http://stackoverflow.com/questions/26699385/spring-boot-yaml-configuration-for-a-list-of-字符串...這就是說,我已經嘗試了'配置'和'組件',但沒有運氣 –

+0

嘗試分享你的代碼,看看我們能否以某種方式幫助你。 – bilak

+0

我想出了這個問題。我沒有提供getters/setters。我已經公開了這個領域,我認爲它會起作用 –

相關問題