一,.properties方式
格式:application-{profile}.properties,用来指定多个环境版本
- application-dev.properties 开发环境
- application-pro.properties 生产环境
- application-test.properties 测试环境
springboot不会直接启动这些配置文件默认采用application.properties配置文件,如果使用别的,需要激活:
- application.properties配置文件中激活
#激活dev
# spring.profiles.active=dev
# 激活test
spring.profiles.active=test
二,yaml/yml多文档块的方式
- application-dev.yml 开发环境
- application-pro.yml 生产环境
- application-test.yml 测试环境
在这三种环境的配置文件中写不同的端口以及不同的配置内容,在项目启动的时候在application.yml文件中指定要实用的环境配置文件,在项目启动的时候就会实用该配置文件。
- application.yml配置文件中激活
spring:
profiles:
active: test #激活测试环境配置文件