[原创] Spring 配置文件中如何读取系统环境变量

假设我们想读取 jboss home,配置文件中的写法如下:
<bean id="wroProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="file:#{systemProperties['jboss.home.dir']}/standalone/configuration/wro.properties" />  
</bean>

注意其中的:file:#{systemProperties['jboss.home.dir']} 部分。
因为 jboss 在启动时,会将 JBOSS_HOME 变量的值赋给 jboss.home.dir 变量,所以在配置文件中,获取 jboss.home.dir 的值即可。

猜你喜欢

转载自yhz61010.iteye.com/blog/2370032