原文路徑:http://www.jb51.net/article/132589.htm
----------------------------------------
默認是profile為dev,可以修改
spring 多文件配置:
1、properties文件
2、YAML文件
一、properties文件
在 Spring Boot 中, 多環境配置的文件名需要滿足 application-{profile}.
properties的格式, 其中{profile}對應你的環境標識, 如下所示。
? application-dev.properties: 開發環境。
? application-test.properties: 測試環境。
? application-prod.properties: 生產環境。
至于具體哪個配置文件會被加載, 需要在 app巨ca巨on.properties 文件中通過
spring.profiles.active 屬性來設置, 其 值 對應配置文件中的{profile}值。 如
spring.profiles.active = test就會加載 application-test.properties配置
文件內容。
二、YAML文件
server: port: 8080
# 默認的profile為dev,其他環境通過指定啟動參數使用不同的profile,比如:
# 測試環境:java -jar xxx.jar --spring.profiles.active=test
# 生產環境:java -jar xxx.jar --spring.profiles.active=prod
spring: profiles: active: dev
#下面這一行務必不能少,區分不同配置,而且必須是三個字符"-"
---
# 開發環境配置
spring:profiles: devdatasource:url: jdbc:mysql://192.168.0.152:3306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false---
# 測試環境配置
spring:profiles: testdatasource:url: jdbc:mysql://192.168.0.152:13306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false---
# 生產環境配置
spring:profiles: proddatasource:url: jdbc:mysql://192.168.0.152:23306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false
使用方法:
通過指定啟動參數使用不同的profile,比如:
測試環境:Java -jar xxx.jar –spring.profiles.active=test
生產環境:java -jar xxx.jar –spring.profiles.active=prod