File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reloaded .properties file with updated changes

 
Rithanya Laxmi
Ranch Hand
Posts: 184
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic