如:开发-测试-生产 等 几种环境 下,多环境的切换
一、application-*.properties 文件下的切换
开发环境配置文件:src/main/resources/application-dev.properties
# 开发环境 配置文件 server.port=8080 server.servlet.context-path=/dev测试环境配置文件:src/main/resources/application-test.properties
# 测试环境 配置文件 server.port=8081 server.servlet.context-path=/test生产环境配置文件:src/main/resources/application-product.properties
# 生产环境 配置文件 server.port=8082 server.servlet.context-path=/product
主核心配置文件:
当需要使用开发环境
# SpringBoot 主核心配置文件 # 激活使用的配置文件 spring.profiles.active=dev
二、 application-*.yml文件下的切换
开发环境配置文件:src/main/resources/application-dev.yml
# 开发环境
server:
port: 8080
servlet:
context-path: /dev
测试环境配置文件:src/main/resources/application-test.yml
# 测试环境
server:
port: 8081
servlet:
context-path: /test
生产环境配置文件:src/main/resources/application-product.yml
# 生产环境
server:
port: 8082
servlet:
context-path: /product
主核心配置文件:
当需要使用开发环境
# SpringBoot 主核心配置文件 # 激活使用的配置文件 spring: profiles: active: dev