Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @值布尔返回';无效的布尔值';真正有价值_Java_Spring_Spring Boot_Annotations - Fatal编程技术网

Java @值布尔返回';无效的布尔值';真正有价值

Java @值布尔返回';无效的布尔值';真正有价值,java,spring,spring-boot,annotations,Java,Spring,Spring Boot,Annotations,我试图简单地从属性文件中获取值,一个布尔值false,如下所示: @PropertySource("classpath:/conf/default/server.properties") ........ @Value("${startup.notify.enabled}") private boolean enabled; 在属性文件中: startup.notify.enabled=true 为什么我会犯这个错误 Caused by: java.lang.IllegalArgumentE

我试图简单地从属性文件中获取值,一个布尔值
false
,如下所示:

@PropertySource("classpath:/conf/default/server.properties")
........
@Value("${startup.notify.enabled}")
private boolean enabled;
在属性文件中:

startup.notify.enabled=true
为什么我会犯这个错误

Caused by: java.lang.IllegalArgumentException: Invalid boolean value [${startup.notify.enabled}]
    at org.springframework.beans.propertyeditors.CustomBooleanEditor.setAsText(CustomBooleanEditor.java:123)
    at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:464)
    at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:437)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:125)
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
这可能是因为占位符
“${startup.notify.enabled}”

很有魅力

编辑

如果与
@Value
一起使用的其他int、String等字段有问题,请确保配置文件中有
属性资源占位符配置器

@Bean
public static PropertySourcesPlaceholderConfigurer pspc() {
    return new PropertySourcesPlaceholderConfigurer();
}

我自己也试过了,现在效果很好。你必须在你的项目中做一些你还没有提到的不同的事情,或者你正在使用一个不同的Spring启动版本。
@Bean
public static PropertySourcesPlaceholderConfigurer pspc() {
    return new PropertySourcesPlaceholderConfigurer();
}