Spring参考文档介绍了有关PropertyPlaceholderConfigurer的内容
PropertyPlaceholderConfigurer不仅会在您指定的Properties文件中查找属性, 还会检查Java
System属性 是否无法找到您要使用的属性。
如上所示,您可以设置一个Java System属性
在开发机器上
-Dprofile=development
在生产机器上
-Dprofile=production
因此,您可以定义全局应用程序上下文设置,如下所示 导入 每个分层的上下文设置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:property-placeholder/> <import resource="service-${profile}.xml"/> <import resource="persistence-${profile}.xml"/> <import resource="security-${profile}.xml"/></beans>请记住,所有位置路径 都相对于进行导入的定义文件
因此,Spring支持这种配置。
通常,最好为此类绝对位置保留一个间接寻址,例如,通过 在运行时针对JVM系统属性解析的 “ $ {…}”占位符。



