來源:how to read System environment variable in Spring applicationContextweb
答案:spring
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']}
app
使用SpringEL表達式來獲取spa
#{systemEnvironment['ENV_VARIABLE_NAME']}
例如:code
<!--上傳文件--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> <property name="uploadTempDir" value="file://#{systemEnvironment['TEMP']}"/> </bean>
可能須要如下依賴blog
<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>