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 8976725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:39+00:00 2026-06-15T19:12:39+00:00

I am loading Properties files to One class and then using the class throughout

  • 0

I am loading Properties files to One class and then using the class throughout the application to get them.

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);
    }

}

and in ApplicationContext.xml

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

Now I want to make sure that Properties file is reloaded whenever it’s changed.

I have one listener class which initializes along with tomcat server.
and I have written below logic for file watcher

TimerTask task = new FileWatcher(new File("c:\\temp-reb\\config\\config.properties")) {
    /*
     * (non-Javadoc)
     * @see com.belgacom.rosy.rebecca.utils.FileWatcher#onChange(java.io.File)
     */
    @Override
    protected void onChange(File file) {
        loadServiceProperties(file);
        loadMetadata();
    }
};

Timer timer = new Timer();
timer.schedule(task, new Date(), Long.valueOf(properties.getProperty("properties.file.timer.schedule"))); // repeat the check every second

problem is

  1. FileWatcher needs path to run, which I don’t want to hardcode
  2. How do I tell spring to call properties to reload explicitly!
  • 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-15T19:12:40+00:00Added an answer on June 15, 2026 at 7:12 pm
    1. FileWatcher needs path to run, which I don’t want to hardcode

    Just give the relative path like a resource directory in same project folder, which you can get using the getResource() method. You can also use the system property to access like user.dir which is the use working directory.

    File f = new File(System.getProperty("user.dir")+ "/test.properties");
    System.out.println(f.getAbsolutePath());
    

    2. How do I tell spring to call properties to reload explicitly!

    The way you are doing it currently seems ok to me. There might be other ways as well, but I don’t see any flaw in the above process.

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

Sidebar

Related Questions

Loading class (View): public class Loading extends View { private long movieStart; private Movie
When loading the class, using method forName() , any static initializers in the class
I was thinking about using the functionality built in the Properties API then I
Currently i have an application that reads and writes several properties from one or
I'm loading properties attributes from a .properties file using Spring as follows: file: elements.properties
I'm trying to use a ClasspathResourceLoader for loading my *.vm files. I have them
I'm trying to use Java class Properties for saving the settings for my application
I was confused using the said method because while loading some properties file people
in my game i'm loading properties files from a specific level folder with this
I have a question about loading properties from custom configuration files. I have tried

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.