1

I'm trying to simply get value from properties file, a boolean value of false like this:

@PropertySource("classpath:/conf/default/server.properties")
........
@Value("${startup.notify.enabled}")
private boolean enabled;

in properties file:

startup.notify.enabled=true

Why am I getting this error?

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)

Can this be because of placeholder "${startup.notify.enabled}"?

lpkej
  • 445
  • 6
  • 23
  • I just tried this myself, and this works fine as it is. You must be doing something different within your project that you haven't mentioned yet or you're using a different Spring boot version. – g00glen00b Jun 27 '19 at 06:36

1 Answers1

11
@Value("#{new Boolean('${startup.notify.enabled}')}")

Works like a charm

EDIT

If you have trouble with other int, String, etc fields used with @Value, make sure you have PropertySourcesPlaceholderConfigurer in your Config file.

@Bean
public static PropertySourcesPlaceholderConfigurer pspc() {
    return new PropertySourcesPlaceholderConfigurer();
}
lpkej
  • 445
  • 6
  • 23