title: Resolving system environment variable using Spring Expression Language
body: <p>I want to resolve system environment variable using `Spring Expression Language' in spring servlet configuration file. My first approach was:</p>
  
  <pre><code> &lt;bean id="propertyConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
       p:location="/WEB-INF/jdbc.#{systemEnvironment.THREAD_ENV}.properties" /&gt;
  </code></pre>
  
  <p>This is throwing below exception:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 18): Field or property 'THREAD_ENV' cannot be found on object of type 'java.util.Collections$UnmodifiableMap'
  </code></pre>
  
  <p>Then I have tried:</p>
  
  <pre><code>&lt;bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.#{systemEnvironment['THREAD_ENV']}.properties" /&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.#{systemEnvironment[THREAD_ENV]}.properties" /&gt;
  </code></pre>
  
  <p>which both fail and resolve to empty string. I am using Tomcat6 and I export this variable just before restarting Tomcat server:</p>
  
  <pre><code>export THREAD_ENV=live;
  /etc/init.d/tomcat6 restart;
  </code></pre>
  
  <p>Would like to mention that all three methods work on some of my Tomcat6 instances but not on all - what could be the reason of such a strange behaviour? Any idea what I am doing wrong?</p>