Announcement Announcement Module
Collapse
No announcement yet.
How to save properties changed by application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to save properties changed by application

    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

  • #2
    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.

    Comment


    • #3
      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.Pr opertyPlaceholderConfigurer">
      <property name="location" value="remote.properties" />
      </bean>

      <bean id="paramConfigService" class="org.springframework.aop.framework.ProxyFact oryBean">
      <property name="target">
      <bean class="org.springframework.remoting.httpinvoker.Ht tpInvokerProxyFactoryBean">
      <property name="serviceUrl" value="http://${serverName}:${httpPort}${contextPath}/remoting/paramConfigService" />
      <property name="serviceInterface" value="com.nbpilot.service.charge.ParamConfigManag er" />
      <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.

      Comment

      Working...
      X