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

  • leveiji7
    started a topic How to reload a properties file in Spring context

    How to reload a properties file in Spring context

    Hello,

    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 :
    Code:
    <bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <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 wd like to change the value of my key my.property.value in the properties file myFile.properties witch is located in classpath, the new value must be reloaded in the Container, now it's seems to be not the way.

    thanks

  • Enrico Pizzi
    replied
    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).

    Leave a comment:

Working...
X