title: Loading properties based on maven profiles?
body: <p>I am using spring 3.2. I am trying to load properties file based on maven profile as below.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;build&gt;
      &lt;resources&gt;
        &lt;resource&gt;
          &lt;directory&gt;src/main/resources&lt;/directory&gt;
          &lt;filtering&gt;true&lt;/filtering&gt;
        &lt;/resource&gt;
      &lt;/resources&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.7&lt;/source&gt;
            &lt;target&gt;1.7&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
  
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.17&lt;/version&gt;
          &lt;configuration&gt;
              &lt;includes&gt;
                  &lt;include&gt;**/*Test.java&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;
  
      &lt;/plugins&gt;
    &lt;/build&gt;
  
    &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;dev&lt;/id&gt;
              &lt;activation&gt;
                  &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
              &lt;/activation&gt;
              &lt;properties&gt;
                  &lt;env&gt;dev&lt;/env&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;prod&lt;/id&gt;
              &lt;properties&gt;
                  &lt;env&gt;prod&lt;/env&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  </code></pre>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations" value="classpath:props/connection-${env}.properties"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>here <code>{env}</code> should be replaced by maven profile.but it is not replacing. am getting below exception.</p>
  
  <p><strong>org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [props/connection-{env}.properties] cannot be opened because it does not exist.</strong></p>
  
  <p>I am loading application context as:</p>
  
  <pre><code>ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
  </code></pre>
  
  <p>when i do <code>clean install</code> {env} value has to be replaced by maven profile.</p>
  
  <p>any help?</p>