I like to use Spring framework's PropertyPlaceholderConfigurer to link to a .properties file to access my application configuration.
However, if a properties entry is missing from properties file, you will get BeanDefinitionStoreException. This is reasonable in most of time. But sometime you will just want to set some default value for certain entry (i.e. new entry that only applicable for new version and you want it to be backward compatible with old version configuration file).
For those scenarios, default value is supported by PropertyPlaceholderConfigurer as well by its setProperties(Properties props) method. Below is how it will look like:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>my_config.properties</value></property>
<property name="properties">
<props>
<prop key="entry.1">123</prop>
</props>
</property>
</bean>
4 comments:
thank you! Really helpful information!
Thanks. Very useful.
Add in
This will override local property definitions if they are found in external property file.
Add in
This will override local property definitions if they are found in external property file.
Post a Comment