【发布时间】:2012-05-27 00:32:05
【问题描述】:
我有一个 Spring 3.1 应用程序。假设它有一个包含以下内容的 XML:
<context:property-placeholder location="classpath:somename.properties" />
<context:property-placeholder location="classpath:xxx.properties" />
我希望 some.properties 始终被加载(假设它存在),但第二个占位符的 xxx 部分将被替换为某个名称,具体取决于活动配置文件。我试过这个:
<beans profile="xx1">
<context:property-placeholder location="classpath:xx1.properties" />
</beans>
<beans profile="xx2">
<context:property-placeholder location="classpath:xx2.properties" />
</beans>
此外,这两个文件的属性具有相同的键但不同的值。
但它不起作用,因为后来的 bean 具有一个属性的占位符,该属性的键在 xx1.properties(和 xx2.properties)中定义,这使 Spring 抱怨在应用程序上下文中找不到该键。
【问题讨论】:
-
你使用 maven 来构建你的项目吗?我相信 Maven 有办法使用过滤器对属性文件名进行令牌替换。
-
我确实使用 Maven,但 Spring 没有提供自己的方法来执行此操作似乎很奇怪。