/**
* 读取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
相关推荐
安当加密10 分钟前
MySQL数据库透明加密(TDE)解决方案:基于国密SM4的合规与性能优化实践JH30731 小时前
第七篇:Buffer Pool 与 InnoDB 其他组件的协作板凳坐着晒太阳1 小时前
ClickHouse 配置优化与问题解决数据库生产实战1 小时前
解析Oracle 19C中并行INSERT SELECT的工作原理AAA修煤气灶刘哥2 小时前
服务器指标多到“洪水泛滥”?试试InfluxDB?阿沁QWQ2 小时前
MySQL服务器配置与管理程序新视界3 小时前
MySQL“索引失效”的隐形杀手:隐式类型转换,你了解多少?Logintern094 小时前
windows如何设置mongodb的副本集XYiFfang4 小时前
【MYSQL】SQL学习指南:从常见错误到高级函数与正则表达式RestCloud5 小时前
在制造业数字化转型浪潮中,数据已成为核心生产要素。然而,系统割裂、数据滞后、开发运维成本高等问题,却像顽固的 “数据枷锁”,阻碍着企业发展。ETLCloud与