title: Dynamically load files on classpath using ReloadableResourceBundleMessageSource
body: <p>I'm new to Spring and am attempting to use it's ReloadableResourceBundleMessageSource class.</p>
  
  <p>I'm attempting to use it so that we no longer have to restart our web app for properties files changes/updates.</p>
  
  <p>I have a web app (Primarily using JSF) and a separate tar component which contains all my properties files.</p>
  
  <p>The structure of the properties tar is as follows:</p>
  
  <pre><code> - CompanyOneMessages.properties
   - CompanyOneMessages_fr_FR.properties
   - CompanyTwoMessages.properties
   - CompanyTwoMessages_fr_FR.properties
   - CompanyThreeMessages.properties
   - CompanyThreeMessages_fr_FR.properties
   - ...
  </code></pre>
  
  <p>This tar is unzipped and deployed to a location on the server which is specified as been on the classpath within the websphere configurations. </p>
  
  <p>I added the following to my applicationContext-config.xml:</p>
  
  <pre><code>&lt;!-- Enable reloading of resource bundles without requiring web-app restart --&gt;
      &lt;bean id="messages"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basenames"&gt;
              &lt;list&gt;  
                  &lt;value&gt;classpath:com/resource/dynamic/CompanyOneMessages&lt;/value&gt;
                  &lt;value&gt;classpath:com/resource/dynamic/CompanyTwoMessages&lt;/value&gt;
                  &lt;value&gt;classpath:com/resource/dynamic/CompanyThreeMessages&lt;/value&gt;              
              &lt;/list&gt;
          &lt;/property&gt;     
          &lt;property name="cacheSeconds" value="1" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Declare location of bean to handle messages and define property reference 
           we will use to reference message properties throughout the presentation layer --&gt;
      &lt;bean id="myappMessages" class="com.myapp.resource.MyAPPMessages"&gt;
          &lt;property name="messages" ref="messages" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>This all works fine.</p>
  
  <p>BUT, it does not fully fix the original problem. 
  Any time I want to add a new company to our application, I will have to add a new line to the applicationContext-config.xml file and redeploy/restart the web app.</p>
  
  <p>I would like to be able to simply drop the new company properties file into the properties tar and for it to be dynamically picked up.</p>
  
  <p>Is it possible to extend the ReloadableResourceBundleMessageSource class in such a way that it will search the class-path for properties files on application start-up and dynamically load all of them?</p>
  
  <h2>Update</h2>
  
  <p>This is what I have so far:</p>
  
  <p>applicationContext-config.xml:</p>
  
  <pre><code>&lt;bean id="messages" class="com.resource.MyAPPReloadableResourceBundleMessageSource"&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>MyAPPReloadableResourceBundleMessageSource:</p>
  
  <pre><code>package com.myapp.resource;
  
  import org.springframework.context.support.ReloadableResourceBundleMessageSource;
  
  public class MyAPPReloadableResourceBundleMessageSource extends ReloadableResourceBundleMessageSource
  {   
      public MyAPPReloadableResourceBundleMessageSource()
      {   
          getResourceBundlesMessages();
  
          // Simply single basename test
          setBasename("classpath:/resource/dynamic/companyOneMessages");      
      }
  
      @Override
      public void setBasename(String baesname)
      {
          System.out.println("In setBasename");
          super.setBasename(baesname);
      }
  
      @Override
      public void setBasenames(String[] baesnames)
      {
          System.out.println("In setBasenames");
          super.setBasenames(baesnames);
      }
  
      private String[] getResourceBundlesMessages()
      {
          String[] propertiesFiles = null;
  
          // How do I get all filenames with .properties under com.resources.dynamic? (location is under classpath)
  
          return propertiesFiles;
      }
  }
  </code></pre>
  
  <p>So all I need is how to get a list of all files under the classpath with .properties extension?</p>
  
  <p>Thanks</p>
  
  <p>Thomas</p>