天天看點

Springboot學習筆記二、 Profile對不同環境提供不同的配置支援

一、可以通過激活指定參數方式快速切換環境

1、多profile檔案形式

1)格式:application-{profile}.properties

2) 一般情況分為:application-dev.properties 、application-prod.properties、application-test.properties、application.properties

Springboot學習筆記二、 Profile對不同環境提供不同的配置支援

3) 當然也可以指定配置檔案

激活方式
1)在application.properties中指定
    spring.profiles.active=dev

2) 指令行 可以直接在測試的時候,配置傳入指令參數
    java-jar spring-boot-demo-config-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

3) 虛拟機參數
    -Dspring.profile.active=dev
           

2、yml配置檔案以文檔塊的形式指定 然後指定profiles.active={環境}

server:
  port: 8081
spring:
  profiles:
    active: dev
---
server:
  port: 8002
spring:
  profiles: dev
---
server:
  port: 8003
spring:
  profiles: prod
---
server:
  port: 8004
spring:
  profiles: test