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
將有串one
和two
的列表中,但它是空的。有人能幫助這裏發生的事情以及如何解決它嗎?
是啊,我有整整增加它它在文檔中提到的方法。與'可選'值設置爲'真正',我用'組件'因爲這個響應>> http://stackoverflow.com/questions/26699385/spring-boot-yaml-configuration-for-a-list-of-字符串...這就是說,我已經嘗試了'配置'和'組件',但沒有運氣 –
嘗試分享你的代碼,看看我們能否以某種方式幫助你。 – bilak
我想出了這個問題。我沒有提供getters/setters。我已經公開了這個領域,我認爲它會起作用 –