spring MVC配置文件中获取环境变量

spring MVC配置文件中如何获取上述环境变量呢?
方式一:使用#{systemEnvironment['USER']}
使用#{systemEnvironment['USER']}
实例
<bean id="alisecurityProperties" class="com.dangdang.config.service.file.FileConfigGroup">
<constructor-arg name="configProfile" ref="fileConfigProfile" />
<constructor-arg name="location" value="classpath:/#{systemEnvironment['USER']}/app.properties" />
</bean>
方式二:使用PropertySourcesPlaceholderConfigurer来简化调用
在使用之前先初始化org.springframework.context.support.PropertySourcesPlaceholderConfigurer
然后直接通过${USER} 来调用

PropertyPlaceholderConfigurer 也可以:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
还可以设置默认值,当获取不到环境变量时,使用默认值
value="classpath:/${sysType:inte}/xxx.properties"

参考:http://stackoverflow.com/questions/26387645/how-to-use-system-environment-variable-as-part-of-propertysource-value
本文介绍在SpringMVC配置文件中如何利用#{systemEnvironment['USER']}
507

被折叠的 条评论
为什么被折叠?



