1、pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prd</id>
<properties>
<env>prd</env>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>dev/*</exclude>
<exclude>prd/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${env}</directory>
</resource>
</resources>
</build>
2、配置文件目录如下图:
3、mvn命令打包
注意:项目中使用了mybatis-generator插件,在使用mvn package命令打包时,mybatis-generator也会执行,导致在dao中自定义的函数被删除。
原因:是因为mybatis-generator插件默认绑定了package的生命周期
解决:在pom中手动设置一下mybatis-generator插件绑定的生命周期即可
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>deploy</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>