将 spring 扩展语言 EL 与 systemProperties 结合使用

Using spring extensions language EL with systemProperties

我设置了以下环境变量:

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

并且在申请中-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 解析器?

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

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