/**
* 读取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
相关推荐
SL_staff20 分钟前
JVS数字底座实践:如何复用企业文档能力快速构建知识类应用sugar__salt22 分钟前
MyBatis ③动态 SQL 完全指南 —— 从条件拼接到批量操作农村小镇哥1 小时前
C#读取CSV文件的方法IMPYLH1 小时前
HTML 的 <embed> 元素油丶酸萝卜别吃2 小时前
Redis 布隆过滤器快速实现深念Y2 小时前
stable-diffusion.cpp 的 FLUX.2 Klein 9B 分步whn19772 小时前
oracle 的ora-19633处理x-cmd2 小时前
用 Rust 打造 AI 时代的 SQL:把重复任务变成可执行文件小弥儿2 小时前
Firecrawl:把整个网页变成 AI 可查询的数据库swordbob2 小时前
mysql数据库,明明有索引为啥不用