java - How to correctly specify a default value in the Spring @Value annotation? -
initially, have following spec:
@value("#{props.isfpl}") private boolean isfpl=false;
this works fine correctly getting value property file:
isfpl = true
however, following expression default results in error:
@value("#{props.isfpl:false}") private boolean isfpl=false;
expression parsing failed; nested exception org.springframework.expression.spel.spelparseexception: el1041e:(pos 28): after parsing valid expression, there still more data in expression: 'colon(:)'
i tried use $ instead of #.
@value("${props.isfpl:true}") private boolean isfpl=false;
then default value in annotation works fine did not correct value properties file:
try $ follows
@value("${props.isfpl:true}") private boolean isfpl=false;
also make sure set ignore-resource-no-found true if property file missing, default value taken.
also, place following in -
the context file if using xm based configuration :
<context:property-placeholder ignore-resource-not-found="true"/>
in configuration class if using java configurations :
@bean public static propertysourcesplaceholderconfigurer propertysourcesplaceholderconfigurer() { propertysourcesplaceholderconfigurer p = new propertysourcesplaceholderconfigurer(); p.setignoreresourcenotfound(true); return p; }
Comments
Post a Comment