1.src/main/resources下创建test和produce文件夹,添加对应的属性文件。
2.src/main/resources下创建默认的开发属性文件。
<build> <plugins> <!-- 不同环境的配置文件选择 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-resources</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <!-- 覆盖原有文件 --> <overwrite>true</overwrite> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <!-- 待处理的资源定义 --> <resources> <resource> <!-- 指定resources插件处理哪个目录下的资源文件 --> <directory>src/main/resources/${package.environment}</directory> <filtering>false</filtering> </resource> </resources> </configuration> <inherited></inherited> </execution> </executions> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>test/**</exclude> <exclude>product/**</exclude> </excludes> <filtering>true</filtering> </resource> </resources> </build> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <package.environment>dev</package.environment> </properties> </profile> <profile> <id>test</id> <properties> <package.environment>test</package.environment> </properties> </profile> <profile> <id>product</id> <properties> <package.environment>product</package.environment> </properties> </profile> </profiles>
原文:https://www.cnblogs.com/yjwfcs/p/12033936.html