【发布时间】:2011-09-13 09:48:07
【问题描述】:
我在使用 maven 3 和加载正确的 .properties 文件时遇到了一些问题。
我想要实现的是:使用 mvn -Plocal 我想加载 setting-local.properties,如果它与 prod 一起运行,我想加载 settings-prod.properties。
它通过使用 mvn -Denv=local 工作,但是当我尝试使用 -Plocal 时,变量没有加载(settings-${env}.properties 不存在)。
我的 pom.xml:
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>local</env>
</properties>
</profile>
</profiles>
在我的应用程序上下文中,我想加载环境变量:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:settings-${env}.properties
</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders">
<value>true</value>
</property>
</bean>
那么问题是什么,不应该双向工作吗?
【问题讨论】:
-
好吧,所以我终于在我的示例中发现了问题所在。我在应用程序上下文中有一个 @ 注释,所以即使我使用过滤它也不起作用,直到我删除注释或使用 maven.apache.org/plugins/maven-resources-plugin/examples/… 转义字符串