1 多Profile文件
我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties或application-{profile}.yml
默认使用application.properties的配置;
2 properties文件模式
2.1 application.properties
server.port=8080
2.2 启动HelloApplication
2.3 application-test.properties
server.port=8081
然后在application.properties中激活改配置文件
- application.properties
server.port=8080
spring.profiles.active=test
2.4 启动HelloApplication
3 yml格式
# 指定端口
server:
port: 8080
# 激活指定环境
spring:
profiles:
active: test
# --- 代表文件分割,将application.yml文件分为多个模块
---
server:
port: 8081
# 环境标识
spring:
profiles: test
---
server:
port: 8082
spring:
profiles: production
4 命令行模式
java -jar 项目名.jar —spring.profiles.active=test;
5 虚拟机模式
-Dspring.profiles.active=test