我正在使用不同的maven配置文件将我的应用程序部署到不同的环境。(使用weblogic-maven-plugin,但我认为这并不重要)
在应用程序中,我使用了Spring Web服务。现在,我想根据环境更改端点。(端点在Spring的applicationContext.xml中定义)
我的想法是从属性文件中读取值。此属性文件将在Mavens包阶段写入(或复制)。
这是个好主意吗?
如果是:如何使用maven创建此属性(或整个文件)。
如果不是:解决这个问题的更好方法是什么?
发布于 2011-11-30 20:16:01
我实现了类似的操作,但将变量放在pom.xml中,而不是放在propreties文件中。因此,我的属性文件中的变量可以由Maven在打包中更改。
首先,我在pom的profile部分定义了这些变量:
<profiles>
<profile>
<id>dev</id>
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<props.debug>true</props.debug>
<props.email>false</props.email>
<what.ever.you.want>value for dev profile</what.ever.you.want>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<props.debug>false</props.debug>
<props.email>true</props.email>
<what.ever.you.want>value for prod profile</what.ever.you.want>
</properties>
</profile>
</profiles>然后激活maven处理和资源过滤。所以在你的构建部分:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>最后,我可以在我的属性文件、配置文件中使用"vars“。例如,在我的项目中,我有一个用于配置电子邮件发送的email.properties文件。属性"sendEmail“指示我是否必须发送电子邮件(prod profile)或在调试(dev profile)中打印它。对于dev profile,这个var将被置为false,而对于profile prod,该属性将具有true值。
sendEmail=${props.email}这不仅适用于属性文件,也适用于XML (我猜适用于每个文本文件)
相反的是:
配置的filtering)
https://stackoverflow.com/questions/8325366
复制相似问题