How to set system properties at run time Spring 3 MVC

We currently have a bean definition below to install javax.net.ssl.trustStore

<bean id="trustStore" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" value="#{@systemProperties}" />
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <props>
            <prop key="javax.net.ssl.trustStore">../path_to/cacerts</prop>
            <prop key="javax.net.ssl.trustStorePassword">changeit</prop>
        </props>
    </property>
</bean>

Is it possible to install javax.net.ssl.trustStore at runtime?
I understand that there is something like:

System.setProperty("javax.net.ssl.trustStore", "D:/cacerts"); 

System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

The problem I encountered with this implementation is that when making changes to the "cacerts" file, such a change will not be reflected if the application is not restarted. I would like to know if there is a way to do this dynamically.

We have a function that changes the "cacerts".

I tried to learn this link, but it's hard for me to understand the logic.

http://java.dzone.com/articles/dynamic-property-management

PS: I'm still new to spring.

Hooray!

+3
source
1

FactoryBean :

public class SysConfigPropertiesFactoryBean implements FactoryBean<Properties> {

    public final boolean isSingleton() {
        return true;
    }

    public Class<Properties> getObjectType() {
        return Properties.class;
    }

    public final Properties getObject() {
        // filtering or any other operation here
        return System.getProperties();
    }

}

bean:

<bean id="sysConfig" class="xxx.SysConfigPropertiesFactoryBean"/>

:

xml:

<bean class="...">
   <property name="targetObject" value="#{sysConfig.property}" />
</bean>

, :

 @Value("#{sysConfig.propertyName}")
 private String propertyValue;

@Autowire Properties:

 @Autowired
 @Qualifier("sysConfig")
 private java.util.Properties systemProperties;
+1

All Articles