springboot maven 配置多环境部署

springboot maven 配置多环境部署

参考文章:here

1. 环境配置文件

spring boot允许你通过命名约定按照一定的格式 application-{profile}.properties来定义多个配置文件

将各环境配置文件放在/src/main/resources/目录下,例如:application-demo.properties

2. POM文件配置

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <!-- 配置默认 -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>demo</id>
        <properties>
            <env>demo</env>
        </properties>
    </profile>
    <profile>
        <id>official</id>
        <properties>
            <env>official</env>
        </properties>
    </profile>
</profiles>

3. 激活配置

基本配置写在/src/main/resources/application.properties中:@env@ 在POM文件中配置

spring.profiles.active=@env@

4. 打包

mvn clean package -Pdev -U -Dmaven.test.skip=true  // 不同环境 -P${profileActive}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值