参数化Maven脚本以在Spring配置之间切换的最佳方法是什么?
我有Maven为Web应用程序构建WAR文件.我有另外的弹簧配置 - 一个用于与模拟对象进行集成测试,一个用于与真实对象一起实时生产.
理想情况下,我希望有一个可以构建WAR文件的Maven构建脚本.目前,我只是在构建之前破解spring配置文件,注释进出模拟和真实对象.
最好的方法是什么?
我建议你使用构建配置文件.
对于每个配置文件,您将定义特定的Spring配置:
<profiles>
<profile>
<id>integration</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>integration</value>
</property>
</activation>
<!-- Specific information for this profile goes here... -->
</profile>
<profile>
<id>production</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>production</value>
</property>
</activation>
<!-- Specific information for this profile goes here... -->
</profile>
...
Run Code Online (Sandbox Code Playgroud)
然后,您将通过为第一个配置文件设置参数env:-Denv=integration为-Denv=production第二个配置文件激活一个配置文件或另一个配置文件.
在每个profile块中,您可以指定特定于您的环境的任何信息.然后properties,您可以指定,plugins等等.在您的情况下,您可以更改资源插件的配置,以包含足够的Spring配置.例如,在集成配置文件中,您可以指定Maven搜索Spring配置文件的位置:
<profile>
<id>integration</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>integration</value>
</property>
</activation>
<build>
<resources>
<resource>/path/to/integration/spring/spring.xml</resource>
</resources>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
513 次 |
| 最近记录: |