Java基础之《maven多环境profiles参数切换》

maven有profiles标签,标识程序的多个环境参数。

1、pom.xml中

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <spring.profiles.active>dev</spring.profiles.active>
        </properties>
        <!--junit测试默认读取文件-->
        <!--打包默认包含配置文件-->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <profile>
        <id>test</id>
        <properties>
            <spring.profiles.active>test</spring.profiles.active>
        </properties>
    </profile>

    <profile>
        <id>uat</id>
        <properties>
            <spring.profiles.active>uat</spring.profiles.active>
        </properties>
    </profile>

    <profile>
        <id>pre</id>
        <properties>
            <spring.profiles.active>pre</spring.profiles.active>
        </properties>
    </profile>

    <profile>
        <id>prd</id>
        <properties>
            <spring.profiles.active>prd</spring.profiles.active>
        </properties>
        
    </profile>
</profiles>

注意activeByDefault是默认的环境选择。如果打包时没有-P xxx这个参数,则junit测试默认读取文件、打包默认包含配置文件用activeByDefault。

2、application.yml

spring:
  profiles:
      active: "@spring.profiles.active@"

3、打包后application.yml会自动替换

spring:
  profiles:
      active: "dev"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值