/**
* 读取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
相关推荐
jiayou648 小时前
KingbaseES 表级与列级加密完全指南GBASE1 天前
G术时刻 |GBase 8s数据库事务并发控制之封锁技术介绍(下)xiezhr2 天前
逛GitHub发现了一款免费的带AI功能的数据库管理工具唐青枫2 天前
MySQL JSON 实战详解:从存储、查询、更新到 JSON_TABLE 与索引吃糖的小孩3 天前
给 QQ AI 机器人设计“可控记忆”:会话摘要、手动长期记忆与角色卡边界笃行3503 天前
金仓数据库数据安全双防线:静态存储加密与传输加密实战笃行3503 天前
金仓数据库物理备份实战:sys_rman 全流程演练与误覆盖抢救笃行3503 天前
金仓数据库逻辑备份实战:从全库导出到 Schema 替换的完整闭环SelectDB4 天前
阶跃星辰基于 SelectDB 构建 PB 级 Agent 可观测平台