Spring application.properties文件中的布尔值?

Dim*_*ims 10 java spring properties-file

是否可以在Spring配置文件中使用布尔值?

我在我的bean中写了以下字段:

@Value("${pdk.populatedemo}")
private boolean populateDemo;
Run Code Online (Sandbox Code Playgroud)

但如果导致以下异常:

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;]
Run Code Online (Sandbox Code Playgroud)

我试过这里

pdk.populatedemo=1;
Run Code Online (Sandbox Code Playgroud)

application.properties.我也尝试过=true其他一些.

dun*_*nni 18

布尔类型的正确值是

pdk.populatedemo=true
Run Code Online (Sandbox Code Playgroud)

1 不是布尔字段的有效值,您不能在属性文件中使用分号作为布尔值(正如您在错误消息中清楚地看到的那样).