概要
Profile是Spring對(duì)不同環(huán)境提供不同配置功能的支持,可以通過(guò)激活、指定參數(shù)等方式快速切換環(huán)境.
使用
多profile文件形式
文件名格式:application-{profile}.properties/yml,例如:
application-dev.properties
application-prod.properties
可以在主配置文件中指定激活哪個(gè)配置文件。
spring.profile.active = dev
yml文檔塊
每個(gè)文檔塊使用---分割
server:
port: 8080
spring:
profiles:
active: prod
---
server:
port: 8081
spring:
profiles: dev
---
server:
port: 8082
spring:
profiles: prod
激活指定profile的三種方式
1.在配置文件中指定 spring.profiles.active=dev(如上)
2.項(xiàng)目打包后在命令行啟動(dòng)
java -jar xxx.jar --spring.profiles.active=dev;
更改運(yùn)行時(shí)的命令
3.虛擬機(jī)參數(shù)
Run-->Edit Configuration-->VM options
-Dspring.profiles.active=dev