Java Spring application.properties 文件中的布尔值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34529216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
boolean values in Spring application.properties file?
提问by Dims
Is it possible to have boolean values in Spring configuration file?
Spring配置文件中是否可以有布尔值?
I wrote the following field in my bean:
我在我的 bean 中写了以下字段:
@Value("${pdk.populatedemo}")
private boolean populateDemo;
but if causes the following exception:
但如果导致以下异常:
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;]
here I tried
在这里我试过
pdk.populatedemo=1;
in application.properties
. I also tried =true
and some others.
在application.properties
。我也试过=true
和其他一些。
采纳答案by dunni
The correct value for a boolean type would be
布尔类型的正确值是
pdk.populatedemo=true
1
is not a valid value for a boolean field and you must not use semicolons in your property file for a boolean value (as you clearly can see in the error message).
1
不是布尔字段的有效值,并且您不能在属性文件中使用分号作为布尔值(正如您在错误消息中清楚地看到的那样)。