Spring application.properties 文件中的布尔值? [英] boolean values in Spring application.properties file?
本文介绍了Spring application.properties 文件中的布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Spring 配置文件中是否可以有布尔值?
Is it possible to have boolean values in Spring configuration file?
我在我的 bean 中写了以下字段:
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;]
这里我试过了
pdk.populatedemo=1;
在 application.properties
中.我也试过 =true
和其他一些.
in application.properties
. I also tried =true
and some others.
推荐答案
布尔类型的正确值是
pdk.populatedemo=true
1
不是布尔字段的有效值,您不得在属性文件中将分号用于布尔值(正如您在错误消息中清楚地看到的那样).
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).
这篇关于Spring application.properties 文件中的布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文