简体   繁体   中英

boolean values in Spring application.properties file?

Is it possible to have boolean values in Spring configuration file?

I wrote the following field in my 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM