Springboot配置文件可以加载以下四个位置:
file:./config/ #第一加载位置
file:./ #第二加载位置
classpath:/config/ #第三加载位置
classpath:/ #第四加载位置
格式:application-xxx.yml
application-dev.yml #开发环境
application-prod.yml #生产环境
application-test.yml #测试环境
只需要在application.yml默认的配置文件配置使用的环境即可切换配置文件
spring:
profiles:
active: prod #当前使用生产环境的配置
在application.yml中用三个横杆进行不同配置环境的定义
#选择何种环境生效
spring:
profiles:
active: dev
#开发环境
---
server:
port: 8081
spring:
profiles: dev
#测试环境
---
server:
port: 8082
spring:
profiles: test
#生产环境
---
server:
port: 8083
spring:
profiles: prod
原文:https://www.cnblogs.com/applesnt/p/12676792.html