🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 配置微服务多环境切换打包 开发的微服务项目有很多的jar,每个jar又分为开发, 测试, 正式环境, 每次打包都很麻烦, 偶尔不注意就会出现把测试库环境打包到正式库, 导致服务不可用 项目已经有对应的 ``` 也有的是叫 application bootstrap.yml bootstrap-dev.yml bootstrap-test.yml bootstrap-prod.yml ``` ### pom.xml中增加配置 ``` <build> <resources> <resource> <directory>src/main/resources</directory> <!--用于替换resources里的变量--> <filtering>true</filtering> </resource> </resources> <!-- 这块是没配置 profiles 前就有的打包插件, 两者没有必然关联 --> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <profiles> <profile> <id>dev</id> <properties> <spring.profiles.active>dev</spring.profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <spring.profiles.active>test</spring.profiles.active> </properties> </profile> <profile> <id>prod</id> <properties> <spring.profiles.active>prod</spring.profiles.active> </properties> </profile> </profiles> ``` ### 修改yml ``` spring: profiles: # 环境配置 active: @spring.profiles.active@ ``` 打包时, idea maven 右上角选择要使用的配置环境,