SpringBoot 多环境 yml 和 properties 配置
properties 配置
- 主配置文件 application.properties
# 开发/测试/生产环境分别对应dev/test/prod
spring.profiles.active=dev
application-dev.properties # 开发环境配置文件
application-prod.properties # 生产环境配置文件
application-test.properties # 测试环境配置文件
application.properties # 主配置文件
- 在启动的时候 加上 --spring.profiles.active= 配置文件后缀 就行了
java -jar xxx.jar --spring.profiles.active=dev
java -jar xxx.jar --spring.profiles.active=prod
java -jar xxx.jar --spring.profiles.active=test
yml 配置
application.yml # 主配置文件
application-dev.yml # 开发环境配置文件
application-pro.yml # 生产环境配置文件
application-test.yml # 测试环境配置文件
spring:
application:
name: # 名字就写 项目的名字就行
profiles:
active: dev # 这里配置启动的时候用哪个环境 启动
java -jar xxx.jar --spring.profiles.active=dev
java -jar xxx.jar --spring.profiles.active=prod
java -jar xxx.jar --spring.profiles.active=test