首先看下项目结构,在resources/properties路径下建三个不同的properties文件。
命名上可以区分一下
然后在pom文件中加入如下配置
最外侧project标签内加入,其中test,pre,prd就是后面打包时候的参数标志,表示用哪个配置文件
<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>
然后在plugin中加入如下配置
<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>
最后打包的时候加入-P 参数,表示采用哪个配置文件
mvn package -P test