【Spring Boot】(6)、Profile

Profile是Spring对不同环境提供不同配置功能的支持,可通过激活、指定参数等方式快速切换环境。

1、多Profile文件(Properties格式)

在主配置文件编写的时候,文件名可以是application-{profile}.properties

  • application.properties: 默认全局配置文件

  • application-dev.properties: 开发环境

  • application-prod.properties: 生产环境

  • application-test.properties: 测试环境


2、yml支持多文档块方式

server:
  port: 8080
spring:
  profiles:
    active: dev

---
server:
  port: 8084
spring:
  profiles: dev


---
server:
  port: 8085
spring:
  profiles: prod


---
server:
  port: 8086
spring:
  profiles: test


3、激活指定Profile

  • 在全局配置文件中指定spring.profiles.active=...来指定当前的环境,并使用对应的application-{profile}.properties或者application.yml所对应profile下的配置作为当前环境使用的配置信息。

  • 虚拟机参数:Edit Configurations ---> VM options ---->-Dspring.profiles.active=...

  • 命令行:

    • 打包用命令java -jar xxxx.jar --spring.profiles.active=...

    • IDEA运行设置:Edit Configurations ---> Program arguments ----> --spring.profiles.active=xx



====================打个广告,欢迎关注====================

QQ:
412425870
微信公众号:Cay课堂

csdn博客:
http://blog.csdn.net/caychen
码云:
https://gitee.com/caychen/
github:
https://github.com/caychen

点击群号或者扫描二维码即可加入QQ群:

328243383(1群)




点击群号或者扫描二维码即可加入QQ群:

180479701(2群)




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值