Spring Reload
Spring Reload
Problem:
1) To make spring configuration properties reloadable without server restart 2) When the file changes, the properties should be read again, and the updated values should be assigned to the original beans properties. The standard Spring answer would be shut down the application context and launch a new one, but often we can be much more flexible without restarting container.
Solution: Download following jar file. http://www.wuenschenswert.net/files/spring-reloaded-2007-05-31.zip Extract zip file & modify DEFAULT_RELOADING_PLACEHOLDER_PREFIX property in <spring-reload-home>\src\java\net\wuenschenswert\spring\ReloadingPropertyPlaceholderConfigurer.java From public static final String DEFAULT_RELOADING_PLACEHOLDER_PREFIX = "#{"; to public static final String DEFAULT_RELOADING_PLACEHOLDER_PREFIX = "${";
and recreate jar file., so that properties with prefix ${ will be recognized by spring-reloader.
Example : <bean id="mybean" class="net.wuenschenswert.spring.example.MyBean"> <property name="cachesize" value="${my.cache.size}"/> </bean> Step 2) copy & paste the following three bean declarations to context file where application reading properties like in previous example. Change location property of configproperties bean according to file path. And keep jar file in classpath.
<bean id="propertyConfigurer" class="net.wuenschenswert.spring.ReloadingPropertyPlaceholderConfigurer"> <property name="properties" ref="configproperties"/> </bean> <!-- regularly reload property files. --> <bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean"> <property name="scheduledTimerTasks"> <bean id="reloadProperties" class="org.springframework.scheduling.timer.ScheduledTimerTask"> <property name="period" value="1000"/> <property name="runnable"> <bean class="net.wuenschenswert.spring.ReloadConfiguration"> <property name="reconfigurableBeans"> <list> <ref bean="configproperties"/> <!-- others... --> </list> </property> </bean> </property> </bean> </property> </bean> Step3) By default spring-reloader will check file changes for every second , we can change period property to value we like.