/**
* 读取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
相关推荐
亚控科技21 小时前
超大型数据中心冷源群控升级:自主可控与智能调控的实践naruto_lnq21 小时前
NumPy入门:高性能科学计算的基础Apple_羊先森21 小时前
ORACLE数据库巡检SQL脚本--4、检查锁阻塞2301_8223650321 小时前
实战:用Python分析某电商销售数据zhangyifang_0091 天前
ClickHouse查询报错:Code: 62. DB::Exception: Max query size exceeded:2301_788756061 天前
Python在2024年的主要趋势与发展方向uoKent1 天前
MySQL示例数据库麦聪聊数据1 天前
利用SQL2API模式重构微服务中的数据查询层占疏1 天前
数据库-BRIN 索引Aloudata1 天前
数据工程实践:智能制造企业如何通过NoETL指标平台为数据资产“瘦身”,实现TCO最优?