前言
不同的环境解释:比如我们开发人员使用开发环境,项目发布时使用生产环境,测试期间使用测试环境
一、Profile是什么?
Profile是Spring对不同的环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境
二、使用步骤
1.多Profile文件
配置文件编写方式application-{profile}.properties/yml
启动主配置文件我们可以发现默认使用的是application.properties/yml中的端口
如果想要更改我们可以在默认的配置文件中进行指定(下图第二行)
此时再次执行主配置文件
@SpringBootApplication
public class SpringBoot02Application {
public static void main(String[] args) {
SpringApplication.run(SpringBoot02Application.class, args);
}
}
结果端口变为了我application-dev.properties指定的端口8081
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
2.使用yml方式
server:
port: 8081
spring:
profiles:
active: dev
---
server:
port: 8082
spring:
profiles: dev
---
server:
port: 8083
spring:
profiles: prod
3、激活方式
1.spring.profiles.active=dev
2.idea配置–spring.profiles.active=dev
3.命令行
总结
希望对你有所帮助