title: How to get the path to a properties file and pass it to a bean at runtime
body: <p>I have a bean that is created by Spring.  The actual class resides in a different JAR than Spring.  This bean is passed a path as a constructor argument.  However, I am having difficulty retrieving a handle to the file.  The file is in WEB-INF/classes/.  I've tried relative pathing based on WEB-INF, but obviously that didn't work.</p>
  
  <p>XML:</p>
  
  <pre><code> &lt;bean id="configurationManager" class="package.ConfigurationManager" 
        scope="singleton"&gt;           
        &lt;property name="configurationMapping"&gt;
              &lt;bean class="package.PropertiesFileConfigurationMapper"&gt;
                  &lt;constructor-arg type="java.lang.String"&gt;
                      &lt;value&gt;/path/to/file&lt;/value&gt;
                  &lt;/constructor-arg&gt;
              &lt;/bean&gt; 
        &lt;/property&gt;                     
  &lt;/bean&gt; 
  </code></pre>
  
  <p>Bean:</p>
  
  <pre><code>public class ConfigurationMapper {
  
      public ConfigurationMapper(String resource) {
              _map = new HashMap&lt;String, String&gt;();
          String property = null;
          BufferedReader reader = null;
          try {
              FileReader file = new FileReader(resourcePath);
              reader = new BufferedReader(file);
              while ((property = reader.readLine()) != null) {
                  if (property.matches("(.+)=(.+)")) {
                      String[] temp = property.split("(.+)=(.+)");
                      _map.put(temp[0], temp[1]);
                  }
              }
          } catch (Exception ex){
              ex.printStackTrace();
          } finally {
              if (reader != null)
                  reader.close();
          }
      }
  
      //other methods to manipulate settings
  }
  </code></pre>
  
  <p>How can I get the proper path to the <code>rm.properties</code> file and pass it to the bean at runtime?</p>
  
  <p>Edit: Added constructor code.</p>
  
  <p>Edit: I got it.  I changed the constructor argument to no longer take a path.  It now takes a Resource, so Spring has found the resource that I wanted loaded.</p>