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

  • Home
  • SEARCH
  • 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 9074901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:44:22+00:00 2026-06-16T18:44:22+00:00

I have written a PropertyUtils class (from internet), which will load the Properties <bean

  • 0

I have written a PropertyUtils class (from internet), which will load the Properties

<bean id="propertiesUtil" class="com.myApp.PropertiesUtil" >
    <property name="locations">
        <list>
            <value>classpath:myApp/myApp.properties</value>         
        </list>
    </property>
</bean>

and a PropertiesUtil class is like below

public class PropertiesUtil extends PropertyPlaceholderConfigurer {

    private static Map<String, String> properties = new HashMap<String, String>();

    @Override
    protected void loadProperties(final Properties props) throws IOException {
        super.loadProperties(props);
        for (final Object key : props.keySet()) {
            properties.put((String) key, props.getProperty((String) key));
        }
    }

    public String getProperty(final String name) {
        return properties.get(name);
    }

}

Later, I can get the property by calling PropertiesUtil.getProperty() method.

But now I want to modify it slightly such that, If the myApp.properties get modified/changed by user, it should be loaded again

Probably I need FileWatcher class

public abstract class FileWatcher extends TimerTask {
    private long timeStamp;
    private File file;

    public FileWatcher(File file) {
        this.file = file;
        this.timeStamp = file.lastModified();
    }

    @Override
    public final void run() {
        long timeStampNew = this.file.lastModified();

        if (this.timeStamp != timeStampNew) {
            this.timeStamp = timeStampNew;
            onChange(this.file);
        }
    }

    protected abstract void onChange(File newFile);
}

but my doubts are

  1. How do I create File object using classpath:myApp/myApp.properties
    (because absolute path is not known)
  2. How do I invoke/call spring to
    load/pass the new myApp.properties to PropetisUtil class [in
    onChange method].
  • 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-06-16T18:44:24+00:00Added an answer on June 16, 2026 at 6:44 pm

    You can use Spring’s ReloadableResourceBundleMessageSource class like below:

    <?xml version="1.0" encoding="UTF-8" ?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
        <bean id="myProperties" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <!-- check property file(s) every 1 second -->
            <property name="cacheSeconds" value="1"/>
            <property name="basenames">
                <list>
                    <value>myApp/myApp</value>
                </list>
            </property>
        </bean>
    
    </beans>
    

    And then you can call MessageSource.getMessage() method to get the property value. Here is an example:

    package com.example;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.MessageSource;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class MyApp {
    public static void main(String[] args) throws InterruptedException {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("myApp/MyApp.xml");
            MessageSource myProperties = (MessageSource) ctx.getBean("myProperties");
            while (true) {
                System.out.println(myProperties.getMessage("myApp.propertyOne", null, null));
                Thread.sleep(1000);
            }
        }
    } 
    

    You can directly call ApplicationContext.getMessage(String code, Object[] args, Locale locale) if you renamed your ‘myProperties’ bean as ‘messageSource’.

    For your web apps, please put your property files outside of your web app’s classpath (because the web server might cache them). For instance, WEB-INF/conf/myApp.properties

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
have written a stochastic simulation in Java, which loads data from a few CSV
I have written a simple .NET webservice, which I will be hosted on a
I have written an AppleScript which when supplied with a Windows network link, will
I have written a bash script which installs a number of packages, however for
I have written this code inside a servlet to delete certain records from three
I have written a raw binary image file into a buffer which is an
I have written program reading a simple text from clients. The program works well
I have written custom delegate methods in ClassFile(B), now i am calling them from

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.