You can achieve this with a combination of MethodInvokingFactoryBeans
Create an internal bean that accesses System.getProperties and an external bean that calls putAll on the properties obtained by the internal bean:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetClass" value="java.lang.System" /> <property name="targetMethod" value="getProperties" /> </bean> </property> <property name="targetMethod" value="putAll" /> <property name="arguments"> <util:properties> <prop key="my.key">myvalue</prop> <prop key="my.key2">myvalue2</prop> <prop key="my.key3">myvalue3</prop> </util:properties> </property> </bean>
(Of course you can only use one bean and the target System.setProperties (), but then you would replace the existing properties, which is not a good idea.
Anyway, here is my little testing method:
public static void main(final String[] args) { new ClassPathXmlApplicationContext("classpath:beans.xml"); System.out.println("my.key: "+System.getProperty("my.key")); System.out.println("my.key2: "+System.getProperty("my.key2")); System.out.println("my.key3: "+System.getProperty("my.key3"));
And here is the conclusion:
my.key: myvalue my.key2: myvalue2 my.key3: myvalue3 java.io.tmpdir: C:\DOKUME~1\SEANFL~1\LOKALE~1\Temp\
Sean Patrick Floyd Jul 27 '10 at 5:26 2010-07-27 05:26
source share