【发布时间】:2014-05-27 22:26:27
【问题描述】:
我想在 spring servlet 配置文件中使用“Spring Expression Language”解析系统环境变量。我的第一个方法是:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.#{systemEnvironment.THREAD_ENV}.properties" />
这是抛出异常:
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'
那我试过了:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.#{systemEnvironment['THREAD_ENV']}.properties" />
和
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.#{systemEnvironment[THREAD_ENV]}.properties" />
都失败并解析为空字符串。我正在使用 Tomcat6,并在重新启动 Tomcat 服务器之前导出此变量:
export THREAD_ENV=live;
/etc/init.d/tomcat6 restart;
想提一下,这三种方法都适用于我的一些 Tomcat6 实例,但并非全部适用——这种奇怪行为的原因是什么?知道我做错了什么吗?
【问题讨论】:
标签: spring environment-variables spring-el