/**
* 读取bootstrap配置文件
*/
@Component
public class YmlUtils {
private static final Map<String, String> confMap = new HashMap(256);
static {
ClassLoader classLoader = YmlUtils.class.getClassLoader();
Yaml yaml = new Yaml();
InputStream bootstrapIn = classLoader.getResourceAsStream("bootstrap.yml");
if (bootstrapIn != null) {
fillConfMap(yaml.loadAs(bootstrapIn, Map.class), confMap, null);
IOUtils.closeQuietly(bootstrapIn);
}
}
private static void fillConfMap(Map<String, Object> sourceMap, Map<String, String> destinationMap, String key) {
sourceMap.forEach((key1, v) -> {
String k = key != null ? key + "." + key1 : key1;
if (v instanceof Map) {
fillConfMap((Map) v, destinationMap, k);
} else {
destinationMap.put(k, String.valueOf(v));
}
});
}
public static String getConfig(String key, String defualtValue) {
String value = confMap.get(key);
return value != null && !"".equals(value.trim()) ? value : defualtValue;
}
public static String getConfig(String key) {
return confMap.get(key);
}
public static String getAppName(){
return getConfig("spring.application.name");
}
}
静态方法获取 配置文件的内容
guoyiguang22023-11-11 9:15
相关推荐
SelectDB3 小时前
SelectDB 是哪个公司的?是国产数据库吗?一篇讲清飞轮科技与 Apache Doris 的关系这个DBA有点耶3 小时前
库内计算推理:一条SQL背后的算子融合,和外挂方案差了几次网络往返这个DBA有点耶5 小时前
函数索引的“完全一致”有多苛刻:写法、字符集、类型,差一处就失效星恒随风5 小时前
MySQL 从零入门(三):表的约束详解Alluxio6 小时前
Alluxio + OCI:为 AI 工作负载实现亚毫秒访问延迟与可扩展吞吐数据库急诊室_阿哲10 小时前
一次加索引建议的复核记录:从报告到签字青瓦梦滋10 小时前
Redis主从复制慧都小妮子11 小时前
Wyn商业智能国产数据库适配:数据接入、分析缓存与审计日志验证清单Joy T12 小时前
Redis Lua 原子限流:Lua 脚本、竞态条件与并发控制杨凯凡12 小时前
MySQL 死锁怎么排查?InnoDB 锁等待与 Spring Boot 整事务重试实战