Announcement Announcement Module
Collapse
No announcement yet.
Reload property file without restarting tomcat Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reload property file without restarting tomcat

    Hi,

    I am new to Spring 3.0 . How can i reload my property file without restarting tomcat ?.

    i used this peace of code in applicationcontext.xml and also used the jar file provided here :
    http://www.wuenschenswert.net/wunschdenken/archives/127

    and i am getting error regarding bean creation.......

    <bean id="configproperties"
    class="net.wuenschenswert.spring.ReloadablePropert iesFactoryBean">
    <property name="location" value="file:src/test/net/wuenschenswert/spring/example/config.properties"/>
    </bean>

    <bean id="propertyConfigurer"
    class="net.wuenschenswert.spring.ReloadingProperty PlaceholderConfigurer">
    <property name="properties" ref="configproperties"/>
    </bean>

    <bean id="mybean" class="net.wuenschenswert.spring.example.MyBean">
    <property name="cachesize" value="#{my.cache.size=100}"/>
    </bean>

    <!-- regularly reload property files. -->
    <bean id="timer" class="org.springframework.scheduling.timer.TimerF actoryBean">
    <property name="scheduledTimerTasks">
    <bean id="reloadProperties" class="org.springframework.scheduling.timer.Schedu ledTimerTask">
    <property name="period" value="1000"/>
    <property name="runnable">
    <bean class="net.wuenschenswert.spring.ReloadConfigurati on">
    <property name="reconfigurableBeans">
    <list>
    <ref bean="configproperties"/>
    <!-- others... -->
    </list>
    </property>
    </bean>
    </property>
    </bean>
    </property>
    </bean>

    needed help very urgentely........

  • #2
    This is not possible as the properties are read during Bean Factory Post Processing phase.

    Comment


    • #3
      Reload property file without restarting tomcat

      Hi dks

      I use a FileMonitor to watch when a properties file changes. When a change is detected I rebuild the application context.

      Essentially the FileListener.fileChanged() method needs to contain:
      Code:
         
       public void fileChanged(File file) {
      	synchronized (monitorObject) { // sync to protect any reading of half-baked stuff
      	    isConfigReloading = true;
      
      	    // applicationContext starts life as ClassPathXmlApplicationContext("applicationContext.xml");
      	    ((ClassPathXmlApplicationContext) applicationContext).refresh(); 
      
      	    isConfigReloading = false;
      	    monitorObject.notifyAll();
      	}
          }
      To prevent half built stuff from being read I have matching sync in the getApplicationContext():
      Code:
         
       public static ApplicationContext getApplicationContext() {
      	synchronized (monitorObject) {
      	    while (isConfigReloading) { // while for spin lock
      		try {
      		    monitorObject.wait();
      		} catch (InterruptedException e) {
      		    // don't try to get a logger
      		    e.printStackTrace();
      		}
      	    }
      	}
      	return applicationContext;
          }

      Comment

      Working...
      X