I have tried to use the new @Value-Annotation of Spring 3.0 to configure the application.
My config file has some properties like
It is referenced in the Spring configuration withCode:month=2010-02 #start_date=2009-12-01 #end_date=2009-12-31 ...
In my central Config class I use the @Value-Annotation to reference these properties:Code:<util:properties id="props" location="file:application.properties" />
As you can see above, the property month is set in the configuration file, start_date and end_date are commented out. They are only neccessary if month is not set.Code:private @Value("#{props.month}") String month; private @Value("#{props.end_date}") String sEndDate; private @Value("#{props.start_date}") String sStartDate;
If I set every property (remove the #) everything is fine. If I start the application with the mentioned configuration I get an exception:
EL1008E: (pos 6): Field or property 'end_date' cannot be found on object of type 'java.util.Properties'
OK, Properties return null if a key is not set. But I think this should not produce an Exception... The PropertyPlaceholderConfigurer can be configured to ignore not existing properties. Is there a possibility to define a default value or ignore properties that are not set with @Value?


Reply With Quote
