SpringBoot的多环境配置

Posted shunWcs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot的多环境配置相关的知识,希望对你有一定的参考价值。

1、可以在resources中定义多个配置文件 :application-dev.properties 、application-prod.properties,然后在主配置文件中(application.properties)中激活哪个配置文件

#激活开发环境
spring.profiles.active=dev

2、可以使用yml配置的多环境文档块(方便)

server:
  port: 8080
spring:
  profiles:
    active: prod

my-swagger:
  title: Swagger2的在线生成API文档
  description: 欢迎来到这里
  version: v1.0.0
  termsOfServiceUrl: 欢迎来到这里
  license: The Apache License
  licenseUrl: http://www.baidu.com

swagger:
  enable: false

---
server:
  port: 8081

spring:
  profiles: dev
---
server:
  port: 8082

spring:
  profiles: prod

3、使用命令行参数激活指定的环境 :java -jar xxxxx.jar --spring.profiles.active=dev

以上是关于SpringBoot的多环境配置的主要内容,如果未能解决你的问题,请参考以下文章

Springboot的多环境配置

吊炸天,springboot的多环境配置一下搞明白了!

吊炸天,springboot的多环境配置一下搞明白了!

吊炸天,springboot的多环境配置一下搞明白了!

SpringBoot在启动时的多环境配置以及加载顺序

springboot-21-maven多环境打包