title: Overriding System property in Spring PropertyPlaceHolderConfigurer for integration testing
body: <p>I'm using a System property  to define the location for an environment-specific properties file.  However, I would like to override that value to something different for integration tests.</p>
  
  <p>Here's my production spring setup. I'm using a custom PropertyPlaceholderConfigurer to resolve some encrypted property file values, but that's not important here:</p>
  
  <pre><code>&lt;-- Spring configuration in file service-spring-beans.xml --&gt;
  &lt;bean class="com.mycompany.MyPropertyPlaceholderConfigurer"&gt;
      &lt;property name="locations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath:properties/${MY_ENVIRONMENT}/${MY_ENVIRONMENT}.properties&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="ignoreResourceNotFound" value="false"/&gt;
      &lt;property name="ignoreUnresolvablePlaceholders" value="true"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>At runtime, we define the value of MY_ENVIRONMENT as a Java system property. This all works as expected. However, for integration tests, I would like to define MY_ENVIRONMENT as "inttest", so the integration-test specific property file properties/inttest/inttest.properties is loaded.</p>
  
  <p>I've tried to use a spring context loaded by the integration-test to set up a String bean with the id MY_ENVIRONMENT:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  
      &lt;context:component-scan base-package="com.mycompany.myclasses"/&gt;
  
  
      &lt;bean class="java.lang.String" id="MY_ENVIRONMENT"&gt;
          &lt;constructor-arg value="inttest"/&gt;
      &lt;/bean&gt;
      &lt;!-- this imports the production spring context --&gt;
      &lt;import resource="classpath:service-spring-beans.xml"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>However, the value of MY_ENVIRONMENT is not resolved , and I get this error when running the integration tests.</p>
  
  <blockquote>
    <p>Caused by:
    org.springframework.beans.factory.BeanInitializationException: Could
    not load properties; nested exception is
    java.io.FileNotFoundException: class path resource
    [properties/${MY_ENVIRONMENT}/${MY_ENVIRONMENT}.properties] cannot
    be opened because it does not exist</p>
  </blockquote>
  
  <p>How can I override MY_ENVIRONMENT at inttest time without passing a System property to the JVM?</p>