
Originally Posted by
pmorelli
Is there any way in spring to replace property placeholders in bean definition files with values from environment variables, similar to the ant ${osenv.*} tags?
The code used at http://forum.springframework.org/showthread.php?t=9640 can be used to initialize a bean using System Properties.
1. Create an InitParameters object:
Code:
<bean id="sysInitParameters"
class="net.sourceforge.jwebutil.util.initparameters.InitParametersFactory"
factory-method="createSystemPropertiesInstance">
<description>System Properties Init Parameters</description>
</bean>
2. Create a bean, initializing it with the appropriate System Properties:
Code:
<bean id="myBean" class="net.sourceforge.jwebutil.util.initparameters.PropertyMapper">
<property name="targetClass"><value>...MyBean</value></property>
<property name="sysInitParameters"><ref bean="properties" /></property>
<property name="properties">
<props>
<prop key="javaVersion">java.version</prop>
<prop key="runtimeName">java.runtime.name</prop>
</props>
</property>
</bean>
3. You can refresh the bean dynamically at any time using the current version of the System Properties:
Code:
PropertyMapManager.DEFAULT.refresh(myBean, true);