I have this property setup
<bean id="preferencePlaceHolder"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations" ref="propertiesLocations" />
</bean>
<beans profile="dev, testing">
<util:list id="propertiesLocations">
<value>classpath:runtime.properties</value>
<value>classpath:dev.properties</value>
</util:list>
</beans>
...
There is a property in runtime.properties like so
doImportOnStartup=false
I would like to occasionally do this
mvn jetty:run -DdoImportOnStartup=true
and have the system property take precedence. How can I achieve this? Thanks.
This might not be exactly want you want, but here's my property loading xml anyway. The locations are loaded in order, so the last found will override earlier one, hence the classpath (i.e. war) one first followed by env specific files on the file system. I prefer this approach as its a 1 time config to point at an external file, but you just change that external file as and when required, no more configuring of Spring or JVM args. The final location is looking for a -Dconfig JVM arg which you give a full path for the override prop file.
Hope this helps.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="searchContextAttributes" value="true" />
<property name="contextOverride" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:*.properties</value>
<value>file:${HOME}/some-env-specific-override.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With