Spring Boot对多环境的支持

方式一:多Profile文件支持 —— 编写多个properties配置文件

主配置文件的名称可以写做application-{profile}.properties

默认使用application.properties

方式二:利用yml文件的多文档块功能

server:
  port: 8080
spring:
  profiles:
    active: dev
---
server:
  port: 8081
spring:
  profiles: dev
---
server:
  port: 8082
spring:
  profiles: prod

激活Profile

示例:

server.port=80
spring.profiles.active=dev

还有一种激活方式,是在项目启动时使用VM options或者Program arguments的方式,不再赘述

java -jar [program-name] --spring.profiles.active=[profile]
-Dspring.profiles.active=[profile]
原文地址:https://www.cnblogs.com/renoside/p/13606699.html