SpringBoot——Profile多环境支持
2024-09-07 06:34:40
1.多profile文件形式
主配置文件编写时, 文件名可以是application-{profile}.properties/yml
默认使用的application.properties的配置.
2.多profile文档块模式
yml支持多文档块模式
可以通过启动时端口号判断启用的环境.
3.激活方式
命令行
配置文件中指定
jvm参数
另:通过程序获取profile的值
https://blog.csdn.net/Fmuma/article/details/82787500
使用profile帮我解决了不同环境使用不同配置的问题,那么如果我们需要在代码中获取这个profile的值怎么处理呢?
@Component
public class ProfileUtil implements ApplicationContextAware { private static ApplicationContext context = null; @Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.context = applicationContext;
} // 获取当前环境参数 exp: dev,prod,test
public static String getActiveProfile() {
String []profiles = context.getEnvironment().getActiveProfiles();
if( ! ArrayUtils.isEmpty(profiles)){
return profiles[0];
}
return "";
}
}
最新文章
- c# 获取项目的根目录
- 找到多个与名为“Login”的控制器匹配的类型
- Kmin
- asp.net 微信企业号办公系统-流程设计--流程步骤设置-数据设置
- Linux 配置本地yum源
- Python3 学习第三弹:异常情况如何处理?
- UVALive-4287 Proving Equivalences 有向图的强连通分量+缩点
- HW2.22
- 转载 VC 2010下安装OpenCV2.4.4
- POJ2782:Bin Packing
- java 基础知识四 流程控制
- javascript---split 和 join 的区别
- springboot(五)过滤器和拦截器
- LeetCode算法题-Diameter of Binary Tree(Java实现)
- python学习第21天
- python数据库多字段插入
- #20175120彭宇辰-实验一《Java开发环境的熟悉》实验报告
- XML技术思想
- python异常处理的两种写法
- IIS7部署网站遇到的问题
热门文章
- YUV视频格式详解(翻译自微软文档)
- vagrant 无法挂载共享目录
- Windows Server 2012 R2 配置IIS
- NumPy 之 存储文件和线性代数
- windows10安装redis
- 最常用MySql数据库备份恢复
- QT,QT/E,Qtopia,qt creator的联系与区别
- python __getattr__ &; __getattribute__ 学习
- Ecshop 2.x-3.x RCE漏洞复现
- Kubernetes架构及相关服务详解