使用spring扩展语言EL和systemProperties

时间:2015-07-25 19:12:46

标签: spring el

我设置了以下环境变量:

export yardstick-spark.aws.key=xxx
export yardstick-spark.aws.secret-key=yyy

在application-context.xml中:

<bean id="aws.creds" class="com.amazonaws.auth.BasicAWSCredentials">
  <constructor-arg value="#{systemProperties['yardstick-spark.aws.key']}" />
  <constructor-arg value="#{systemProperties['yardstick-spark.aws.secret-key']}" />

但环境变量不可用:

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.amazonaws.auth.BasicAWSCredentials]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Access key cannot be null.
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:270)
    ... 45 more

是否需要额外的步骤 - 例如设置EL解析器?

1 个答案:

答案 0 :(得分:1)

那些不是系统属性,它们是环境属性。使用

<constructor-arg value="#{systemEnvironment['yardstick-spark.aws.key']}" />