主要通过配置pom来实现!!
1、resources下加入各环境的配置
2、pom文件中加入以下几部分
<profiles> <profile> <id>dev</id> <properties> <profileActive>enviroment/dev</profileActive> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profileActive>enviroment/test</profileActive> </properties> </profile> </profiles>
<build> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>*/dev/*.properties</exclude> <exclude>*/test/*.properties</exclude> </excludes> <filtering>true</filtering> </resource> </resources>
<pluginManagement> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> <configuration> <webResources> <resource> <directory>src/main/resources/${profileActive}</directory> <targetPath>WEB-INF/classes</targetPath> <filtering>true</filtering> </resource> </webResources> </configuration> </plugin> </plugins> </pluginManagement>
</build>
3、在打包的时候我们添加上-P参数,-P后跟对应环境,即可打包对应的配置文件啦