1、多Profile文件
在写主配置文件时,文件名可以是 application-{profile}.properties/yml
默认使用application.properties的配置
# application.properties
server.port=8081
spring.profiles.active=dev // 在application.properties配置文件中指定激活Profile,此时application.properties是主配置文件
# application-dev.properties
server.port=8082
# application-prod.properties
server.port=8083
2、使用yml配置多文档块方式
server:
port: 8081
spring:
profiles:
active: dev // 激活profile ,如果不激活默认是8081
---
server:
port: 8083
spring:
profiles: dev
---
server:
port: 8084
spring:
profiles: prod
3、命令行方式:支持properties和yml文件
--spring.profiles.active=prod
![](https://img.haomeiwen.com/i2765653/688311f55074f1b1.png)
4、命令行直接运行jar包的时,增加命令行参数
java -jar /Users/aaa/spring-test01/my-springboot-demo02/target/my-springboot-demo02-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
![](https://img.haomeiwen.com/i2765653/ebf7f2bc2cc45ec5.png)
网友评论