aspose file tools*
The moose likes Spring and the fly likes  Reloaded .properties file with updated changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark " Reloaded .properties file with updated changes" Watch " Reloaded .properties file with updated changes" New topic
Author

Reloaded .properties file with updated changes

Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Hi,

I have a question , I am looking to reload a file properties in Spring context without reloading all Context.

For example, this is an extract of my SpringContext.xml :

Code:
<bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:myFile.properties</value>
</property>
</bean>


<bean id="myBean" class="com.my.company.MyService">

<property name="myProperty" value="${my.property.value}"/>


</bean>

I would like to change the value of my key "my.property.value" in the properties file myFile.properties which is located in classpath, the new value must be reloaded in the Container, now it's seems to be not the way. How to reload the properties and get the updated values populated in the spring MyService class?

Thanks.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

You could either read this property from the database and make use of the @Cacheable and perhaps some sort of ehcache time to live setting to re-read the properties when they are accessed after that time is exceeded. Or you could use the re-loadable properties. However there is not a good way to do it with the property source configurer.


Here is a solution someone came up with using java 7 features
http://www.morgan-design.com/2012/08/reloadable-application-properties-with.html


There are some other work arounds you can find by googling around. You could also see if you could make things work with http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/context/support/ReloadableResourceBundleMessageSource.html

Remember with the newer PropertySourceConfigurer you get your properties registered in the environment. This means you can do




If you took an approach of registering your changed properties with the Spring environment you would not need to worry about changing bean injections, as it looks it up from the environment.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reloaded .properties file with updated changes