I have a bean which is populating properties using the @Value annotation like this
@Value("${propbean.value : 'None'}")
private String value;
In my application context I have the following configuration
<bean id="propbean"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="file:${path}/values.properties"
p:ignoreResourceNotFound="true"
p:ignoreUnresolveablePlaceholders="true" />
When the values.properties file is not present, the defaults 'None' are being set as expected, however when the properties file is present, the default values are still being used, even though I receive a log message that the properties file was loaded from the PropertyPlaceholderConfigurer
190315 14.23.44,517 {} {} {} INFO (PropertiesLoaderSupport.java:172) Loading properties file from URL [file:/path/to/file/values.properties]
I need the default values to take effect only when the properties file is missing and/or the placeholders are not resolveable; not all the time. I have also tried using SPEL, but because this is a PropertyPlaceholderConfigurer object as opposed to using the directive the SPEL solution doesn't work for me. It's my understanding that when using the ${value : default} format for placeholders that the default is only substituted when the value is null, however if I remove the " : 'None'" from the value placeholder the property resolves correctly!
Aucun commentaire:
Enregistrer un commentaire