title: Environment variable in Spring property file
body: <p>I'm trying to use an environment variable inside a Spring property file but it doesn't seem to work</p>
  
  <p>where the app is running</p>
  
  <pre><code>export TEST_VAR=hello
  </code></pre>
  
  <p>myapp.properties</p>
  
  <pre><code>test.variable=${TEST_VAR}
  enter code here
  </code></pre>
  
  <p>But when I test, the test.variable doesn't translate to hello but stays ${TEST_VAR}.</p>
  
  <p>How can I get Env variable from within that file?</p>
  
  <p>I load the property file this way</p>
  
  <pre><code>&lt;bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
      &lt;property name="singleton" value="true" /&gt;
      &lt;property name="ignoreResourceNotFound" value="false" /&gt;
      &lt;property name="locations"&gt;
        &lt;list&gt;
          &lt;value&gt;classpath:myapp.properties&lt;/value&gt;
          &lt;value&gt;file://#{systemProperties['myApp.configurationFile']}&lt;/value&gt;
        &lt;/list&gt;
      &lt;/property&gt;
    &lt;/bean&gt;
  
  &lt;bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"&gt;
      &lt;property name="properties" ref="props" /&gt;
    &lt;/bean&gt;
  
    &lt;bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="properties" ref="props" /&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>myApp.configurationFile is a system variable I pass when tomcat starts up through -DmyApp.configurationFile=...</p>