1. 程式人生 > >Spring boot 使用YML檔案配置多環境

Spring boot 使用YML檔案配置多環境

兩種配置方式 1:在一個yml檔案中,2:在多個yml檔案中

1 一個yml檔案

application.yml

spring:
  profiles:
    active: dev

---
#開發環境配置
spring:
  profiles: dev

server:
  port: 1000


---
#測試環境配置
spring:
  profiles: stg

server:
  port: 1001


---
#生產環境配置
spring:
  profiles: prd

server:
  port: 1002

2 多個yml檔案

application.yml

spring:
  profiles:
    active: dev

application-dev.yml

server:
  port: 1000

application-stg.yml

server:
  port: 1001

application-prd.yml

server:
  port: 1002

廢話不多說,簡單明瞭。

相關推薦

no