autoConfig 之多环境打包

最近项目中使用了 autoConfig 工具;

​​// pom文件中定义多个环境

<profiles>
        <profile>
            <id>test</id>
            <properties>
                <autoconfig.properties>antx_test.properties</autoconfig.properties>
            </properties>
        </profile>
        <profile>
            <id>pre</id>
            <properties>
                <autoconfig.properties>antx_pre.properties</autoconfig.properties>
            </properties>
        </profile>
        <profile>
            <id>prd</id>
            <properties>
                <autoconfig.properties>antx_prd.properties</autoconfig.properties>
            </properties>
        </profile>
    </profiles>

// pom 中使用插件​

<plugin>
         <groupId>com.alibaba.citrus.tool</groupId>
          <artifactId>autoconfig-maven-plugin</artifactId>
           <version>1.2</version>

            <configuration>
               <userProperties>src/main/resources/properties/${autoconfig.properties}</userProperties>
            </configuration>

            <executions>
                  <execution>
                      <phase>package</phase>
                      <goals>
                          <goal>autoconfig</goal>
                      </goals>
                  </execution>
            </executions>
</plugin>

使用 mvn package -P test 就可以打 test 环境的包 ​; 

​打包时,会利用各自环境指定的配置文件去替换 autoConfig.xml 中 script 标签对应配置文件中的占位符;

antoConfig 文件中的一部分如下:

<script>
        <generate template="application.properties.vm" destfile="WEB-INF/classes/application.properties" />
 </script>

application.propertities 文件中如下:

datasource.slave.host=${datasource.slave.host}
datasource.slave.port=${datasource.slave.port}
datasource.slave.db=${datasource.slave.db}

参考:

https://blog.csdn.net/lw_power/article/details/47174421

https://my.oschina.net/zimingforever/blog/310314

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值