• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

Reloaded .properties file with updated changes

Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 :

<bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="locations">

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

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


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?

Posts: 1682
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

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.
    Bookmark Topic Watch Topic
  • New Topic