Spring Boot项目中application.yml多环境配置

配置步骤

首先在application.yml中添加beetl模板支持和不同环境配置

# 热加载beetl支持
beetl:
  resource-auto-check: true
# 多环境支持
spring:
  profiles:
    active: "@spring.active@"
  main:
    allow-bean-definition-overriding: true

resource目录下添加不同环境的application文件
在这里插入图片描述
在文件中添加开发环境和部署环境的配置:例如数据库配置
本地开发环境配置
在这里插入图片描述
部署环境的配置:
在这里插入图片描述
紧接着修改pom.xml文件:
<project></project>标签中添加如下代码:

<!-- 开发,部署环境配置 -->
<profiles>
    <profile>
        <id>local</id>
        <properties>
            <spring.active>local</spring.active>
        </properties>
        <!-- 默认使用开发环境 -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>online</id>
        <properties>
            <spring.active>online</spring.active>
        </properties>
    </profile>
</profiles>

更新pom文件。

效果展示:

最后就可以通过切换这个来打包发布了
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值