/**
* 读取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
相关推荐
历程里程碑11 小时前
53 多路转接select闪电悠米11 小时前
黑马点评短信登录02_redis_token_loginj7~11 小时前
【MYSQL】 mysql库和表的操作--详解ECT-OS-JiuHuaShan11 小时前
什么是认知,认知的本质是什么?2301_7815714220 小时前
Golang格式化输出占位符都有什么_Golang fmt占位符教程【通俗】养肥胖虎20 小时前
RAG学习笔记(3):区分数据库检索与RAG的使用场景_ku_ku_20 小时前
数据库系统原理 · 数据库应用开发 · 自学总结No8g攻城狮21 小时前
【人大金仓】wsl2+ubuntu22.04安装人大金仓数据库V9山峰哥21 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘代码中介商21 小时前
Redis入门:5大数据类型全解析