Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3314436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:13:57+00:00 2026-05-17T22:13:57+00:00

I have a property file and using Spring property place holder, I set values

  • 0

I have a property file and using Spring property place holder, I set values to the Spring beans. Now, this property file may be modified during the run time. Is there a way to refresh the properties of the Spring beans with this newly modified property value? Especially, I have many singleton beans? How can I refresh them with the new values? Is there already a solution to this or should it be custom coded? If it doesn’t already exist, can someone please give the best approach to achieve this? Thanks!

PS: My application is a batch application. I use Spring based Quartz configuration to schedule the batches.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:13:58+00:00Added an answer on May 17, 2026 at 10:13 pm

    I’ll leave this in for reference, but the updated answer is below the divider:

    Well the ConfigurableApplicationContext interface contains a refresh() method, which should be what you want, but the question is: how to access that method. Whichever way you do it, you’ll start with a bean that has a dependency of type ConfigurableApplicationContext:

    private ConfigurableApplicationContext context;
    @Autowired
    public void setContext(ConfigurableApplicationContext ctx){
        this.context = ctx;
    }
    

    Now the two basic options I’d suggest would be to either

    1. use the Task Execution Framework and let your bean watch the property resources regularly, refreshing the ApplicationContext when it finds changes or
    2. expose the bean to JMX, allowing you to manually trigger the refresh.

    Referring to comments: since it seems impossible to refresh the entire context, an alternative strategy would be to create a properties factory bean and inject that into all other beans.

    public class PropertiesFactoryBean implements FactoryBean<Properties>{
    
        public void setPropertiesResource(Resource propertiesResource){
            this.propertiesResource = propertiesResource;
        }
    
        private Properties value=null;
        long lastChange = -1L;
    
        private Resource propertiesResource;
    
        @Override
        public Properties getObject() throws Exception{
            synchronized(this){
                long resourceModification = propertiesResource.lastModified();
                if(resourceModification != lastChange){
                    Properties newProps = new Properties();
                    InputStream is = propertiesResource.getInputStream();
                    try{
                        newProps.load(is);
                    } catch(IOException e){
                        throw e;
                    } finally{
                        IOUtils.closeQuietly(is);
                    }
                    value=newProps;
                    lastChange= resourceModification;
                }
            }
            // you might want to return a defensive copy here
            return value;
        }
    
        @Override
        public Class<?> getObjectType(){
            return Properties.class;
        }
    
        @Override
        public boolean isSingleton(){
            return false;
        }
    
    }
    

    You could inject this properties bean into all your other beans, however, you would have to be careful to always use prototype scope. This is particularly tricky inside singleton beans, a solution can be found here.

    If you don’t want to inject lookup methods all over the place, you could also inject a PropertyProvider bean like this:

    public class PropertiesProvider implements ApplicationContextAware{
    
        private String propertyBeanName;
        private ApplicationContext applicationContext;
    
        public void setPropertyBeanName(final String propertyBeanName){
            this.propertyBeanName = propertyBeanName;
        }
    
        @Override
        public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException{
            this.applicationContext = applicationContext;
        }
    
        public String getProperty(final String propertyName){
            return ((Properties) applicationContext.getBean(propertyBeanName)).getProperty(propertyName);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property
I have a Property File like this: frame.server.dev=mark.is.cool frame.server.test=chris.is.cool frame.server.qa=mitch.is.cool frame.server.prod=cory.is.cool I need to
I have an Item Writer as below: <beans:property name=lineAggregator> <beans:bean class=org.springframework.batch.item.file.transform.FormatterLineAggregator> <beans:property name=fieldExtractor> <beans:bean
i'm using Spring-WS and have the following spring-ws-servlet.xml file. The injection of defaultURI and
I am using Spring 3.0. Can i read a property file from a localdrive
I have a property file with the following junit.version=3.8.1 dbcp.version=5.5.27 oracle.jdbc.version=10.2.0.2.0 I try to
I have an XML file and I have to convert it into a property
I have an entity called File, I created a partial class with a property
I am using spring MVC 3. I have been trying to access the attributes
Using Roo, and I've got a property called 'imagesBaseDir' in a property file called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.