来源:how to read System environment variable in Spring applicationContext

答案:

In order to access system environment variable, that is OS level variables as amoe commented, we can simply use "systemEnvironment" instead of "systemProperties" in that EL. Like #{systemEnvironment['ENV_VARIABLE_NAME']}

 

使用SpringEL表达式来获取

#{systemEnvironment['ENV_VARIABLE_NAME']}

例如:

 <!--上传文件-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="uploadTempDir" value="file://#{systemEnvironment['TEMP']}"/>
    </bean>

 

可能需要以下依赖

  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.2.5.RELEASE</version>
    </dependency>   
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.2.5.RELEASE</version>
    </dependency>

 

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2022-01-02
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2022-02-12
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-05-27
  • 2021-11-27
相关资源
相似解决方案