多环境启动

一、Yml 配置文件

通过三个短横线区分不同环境的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 设置启用的环境
spring:
profiles:
active: dev
---

# 开发环境
spring:
profiles: dev
server:
port: 8080
---

# 生产环境
spring:
profiles: prod
server:
port: 80
---

# 新配置语法
spring:
config:
activate:
on-profile: beta
server:
port: 9090

二、properties 配置文件

properties 文件根据配置文件名区分环境

application.properties

1
spring.profiles.active=dev

application-dev.properties

1
server.port=8080

application-prod.properties

1
server.port=80

多环境启动
https://blog.pangcy.cn/2023/03/27/后端编程相关/java/springboot/多环境启动/
作者
子洋
发布于
2023年3月27日
许可协议