title: Dynamically loading properties file using Spring
body: <p>I have written a PropertyUtils class (from internet), which will load the Properties</p>
  
  <pre><code>&lt;bean id="propertiesUtil" class="com.myApp.PropertiesUtil" &gt;
      &lt;property name="locations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath:myApp/myApp.properties&lt;/value&gt;         
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and a PropertiesUtil class is like below</p>
  
  <pre><code>public class PropertiesUtil extends PropertyPlaceholderConfigurer {
  
      private static Map&lt;String, String&gt; properties = new HashMap&lt;String, String&gt;();
  
      @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);
      }
  
  }
  </code></pre>
  
  <p>Later, I can get the property by calling PropertiesUtil.getProperty() method.</p>
  
  <p>But now I want to modify it slightly such that, If the myApp.properties get modified/changed by user, it should be loaded again</p>
  
  <p>Probably I need FileWatcher class</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>but my doubts are</p>
  
  <ol>
  <li>How do I create File object using classpath:myApp/myApp.properties
  (because absolute path is not known) </li>
  <li>How do I invoke/call spring to
  load/pass the new myApp.properties to PropetisUtil class [in
  onChange method].</li>
  </ol>