Announcement Announcement Module
No announcement yet.
How to reload a properties file in Spring context Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to reload a properties file in Spring context


    I have a question for you, I am looking to be able 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.PropertyPlaceholderConfigurer">
            <property name="locations">
        <bean id="myBean" class="">
            <property name="myProperty" value="${}"/>
    I wd like to change the value of my key in the properties file witch is located in classpath, the new value must be reloaded in the Container, now it's seems to be not the way.


  • #2
    You can't. Placeholders are resolved before beans instantiation (which is at application startup unless you specify lazy-loading). This is because values are needed to be dependency-injected in beans. Thus, beans are created with the properties read at application startup, and those properties don't change unless you re-set them programmatically one by one by.

    Just refresh the context: unless you have zillions of beans defined (or classes to scan for components, if you use annotation-driven DI) it will only take a few seconds, which is sufferable if you don't need to do it too often (I assume your properties files don't change like every minute or so).