title: Load environment-specific properties for use with PropertyPlaceholderConfigurer?
body: <p>This seems like a pretty common problem, but I haven't found any sort of consensus on the best method, so I'm posing the question here.</p>
  
  <p>I'm working on a command-line Java application using Spring Batch and Spring. I'm using a properties file along with a PropertyPlaceholderConfigurer, but I'm a little unsure of the best way of handling the properties files for multiple environments (dev, test, etc.). My Googling is only turning up programmatic ways of loading the properties (i.e., in the Java code itself), which doesn't work for what I'm doing.</p>
  
  <p>One approach I've considered is simply placing each environment's properties file on the server and adding the file's directory to the classpath via a command-line argument, but I've been having trouble loading the file using that method.</p>
  
  <p>The other method I'm considering is to just include all the properties files in the jar and use a system property or command line argument to fill in the name of the properties file at runtime, like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="locations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath:job.properties.${env}&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I lean towards the latter solution, but I'm also looking to see if there's a better method I'm overlooking.</p>
  
  <p>I should also mention that I have to make the substitution at runtime rather than in the build. The process I'm constrained to use requires a single build which will be promoted through the environments to production, so I'm unable to use substitution ala Maven or Ant.</p>