I want to enable a system environment variable using the `Spring Expression Language 'in the spring servlet configuration file. My first approach:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.#{systemEnvironment.THREAD_ENV}.properties" />
This is an exception:
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'
Then I tried:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.#{systemEnvironment['THREAD_ENV']}.properties" />
and
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.#{systemEnvironment[THREAD_ENV]}.properties" />
which both fail and resolve the empty string. I use Tomcat6, and I export this variable just before rebooting the Tomcat server:
export THREAD_ENV=live; /etc/init.d/tomcat6 restart;
I would like to mention that all three methods work on some of my Tomcat6 instances, but not all - what could be causing this strange behavior? Any idea what I'm doing wrong?
spring spring-el environment-variables
mkorszun
source share