java - IllegalArgumentException: Invalid boolean value when injecting property to boolean in Spring -
in spring boot attempt inject boolean value instance variable enviroment property set (enabled=true
).
@value("${enabled}") private boolean enabled;
however spring cannot resolve reason , reports:
caused by: java.lang.illegalargumentexception: invalid boolean value [${enabled}]
it seems not replace expression ${enabled}
property value.
what needs set ? why doesn't work default ?
as mentioned in comments, missing propertysourcesplaceholderconfigurer bean definition. here's example of how configure within java:
@configuration public class propertyconfig { private static final string property_filename = "app.properties"; // change needed. /** * instance necessary spring load property file , allow access * through @value(${propertyname}) annotation. note bean must static * in order work current spring behavior. */ @bean public static propertysourcesplaceholderconfigurer properties() { propertysourcesplaceholderconfigurer pspc = new propertysourcesplaceholderconfigurer(); resource[] resources = new classpathresource[] { new classpathresource(property_filename) }; pspc.setlocations(resources); pspc.setignoreunresolvableplaceholders(true); return pspc; } }
Comments
Post a Comment