![](/img/trans.png)
[英]Spring Configuration file not reading values from application.properties
[英]boolean values in Spring application.properties file?
是否可以在Spring配置文件中使用布爾值?
我在我的bean中寫了以下字段:
@Value("${pdk.populatedemo}")
private boolean populateDemo;
但如果導致以下異常:
Could not autowire field: private boolean com.inthemoon.pdk.data.DatabaseService.populateDemo; nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert value of type [java.lang.String] to required type [boolean]; nested exception is java.lang.IllegalArgumentException:
Invalid boolean value [1;]
我試過這里
pdk.populatedemo=1;
在application.properties
。 我也嘗試過=true
和其他一些。
布爾類型的正確值是
pdk.populatedemo=true
1
不是布爾字段的有效值,您不能在屬性文件中使用分號作為布爾值(正如您在錯誤消息中清楚地看到的那樣)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.