Java后端使用mvn区分dev,pro,local环境
【摘要】 一,pom.xml配置local代表本地环境dev代表开发环境pro代表生产环境设置默认环境使用dev <!--环境配置--> <profiles> <profile> <id>local</id> <properties> <!-- 环境标识,需要与配置文件的名称相对应 --> ...
一,pom.xml配置
local代表本地环境
dev代表开发环境
pro代表生产环境
设置默认环境使用dev
<!--环境配置-->
<profiles>
<profile>
<id>local</id>
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<activatedProperties>local</activatedProperties>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pro</id>
<properties>
<activatedProperties>pro</activatedProperties>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<!--配置文件路径 -->
<directory>src/main/resources</directory> <!--这里对应项目存放配置文件的目录-->
<!--开启filtering功能 -->
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<!--创建一个自动可执行的jar或war文件 -->
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
二,yml文件配置
spring:
profiles:
active: @activatedProperties@
三,mvn编译命令
-P dev 指定使用dev配置
-P pro 指定使用pro配置
-P local 指定使用local配置
mvn clean install package -P pro -Dmaven.test.skip=true
如不指定 默认使用dev配置
mvn clean install package -Dmaven.test.skip=true
四,验证
启动后会输出使用的配置
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
技术火炬手2019/06/19 11:12:111楼编辑删除举报
Vv2019/06/20 06:35:33编辑删除举报