PDA

View Full Version : How to save properties changed by application


zsulkin
Aug 25th, 2004, 07:12 AM
After instantion of the bean via BeanFactory its properties could be changed by application. I want these properties to be saved and restored when application starts next time. Does Spring provide API that support such behavior? I understand that I could modify xml or properties file from application but is it a recommended way?

Thanks,
Zahar

katentim
Aug 25th, 2004, 07:39 AM
You can implement org.springframework.beans.factory.InitializingBean or specify an init-method for the bean, and implement you own way of restoring persisted properties - overwriting the default values in Spring's context. For example:

<bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/>

public class ExampleBean {
public void init() {
// do some initialization work
}
}

I wouldn't recommend modifying the Spring context XML (if that's what you're suggesting), as this get's out of sync. with your original source repository.

greateWei
May 22nd, 2006, 10:33 PM
I am using spring http-invoker, the client side spring applicationContext including two cofigure file:

remote.properties file,the content as follow:

serverName=localhost
httpPort=8848
contextPath=/PMIS


applicationContext_remote.xml file, the content as follow:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="location" value="remote.properties" />
</bean>

<bean id="paramConfigService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="org.springframework.remoting.httpinvoker.HttpInvok erProxyFactoryBean">
<property name="serviceUrl" value="http://${serverName}:${httpPort}${contextPath}/remoting/paramConfigService" />
<property name="serviceInterface" value="com.nbpilot.service.charge.ParamConfigManager" />
<property name="httpInvokerRequestExecutor" ref="httpInvokerExecutor"/>
</bean>
</property>


NOTE: the remote invoker url "http://${serverName}:${httpPort}${contextPath}"

so when the server IP or Port has changed, how can i modify properties file.

thanks.