/**
* 读取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
相关推荐
持敬chijing3 小时前
Web渗透之SQL注入-二次注入(Second-Order SQL Injection)数据库小学妹3 小时前
PostgreSQL迁移到国产数据库怎么做?评估、改造、上线全流程实操指南x***r1513 小时前
Redis Desktop Manager 0.8.8 安装教程(Windows redis-desktop-manager-0.8.8.384详细步骤)initialize13064 小时前
Postgresql(Oracle兼容) 到Oracle19.9字符语义稷下元歌4 小时前
七天学会plc 加机器视觉完整笔记:S7-1200 数据类型、存储区与寻址方式(I/Q/M/DB 详解)。潮起鲸落入海4 小时前
mysql 5.x源码安装睡不醒男孩0308235 小时前
第一篇:多云与多模态时代的企业级数据库云管理平台(DBaaS)选型指南小二·5 小时前
向量数据库实战炘爚5 小时前
Phase 5:MySQL 连接池j_xxx404_6 小时前
MySQL库操作硬核解析:字符集、校验规则、大小写比较、备份恢复与连接排查