Profile

1、多Profile文件

我们在主配置文件编写的时候,文件名可以是:application-{profile}.properties/yml

默认使用application.properties的配置

image-20200107164135047

2、yml支持多文档块方式

通过—将文档分成多文档块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server:
port: 8081
spring:
profiles:
active: prod
#文档块一
---
server:
port: 8083
spring:
profiles: dev
#文档块二
---
server:
port: 8084
spring:
profiles: prod #指定属于哪个环境
#文档块三

3、激活指定profile

配置文件中指定

使用spring.profiles.active激活指定profile

  • application.properties

image-20200107164614552

  • application.yml

image-20200107165131162

程序参数指定

程序参数中添加–spring.profiles.acprotive激活指定profile

image-20200107165529135

命令行指定

将程序打包成一个jar包,在命令行中输入java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar –spring.profiles.active=dev;

image-20200107165905505

虚拟机参数指定

在VM options中添加-Dspring.profiles.active=dev

image-20200107170114180