/**
* 读取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
相关推荐
天天进步20153 分钟前
Pixelle-Video 源码解析 #18:声音克隆功能:参考音频如何影响解说效果?不懂的浪漫32 分钟前
ToDesk 连接 Linux 后分辨率过低的解决方法布莱克6051 小时前
Redis 详解:从核心数据结构到高可用架构冰暮流星2 小时前
mysql之左外连接与右外连接jyOverQ2 小时前
MySQL 联合索引怎么用?最左匹配原则到底是什么意思?oradh2 小时前
Oracle enq: US - contention 等待事件总结姚不倒3 小时前
etcd 学习系列(一):从业务需求出发,理解 etcd 是什么susplus3 小时前
【linux应用软件编程】数据库sqlite3SelectDB3 小时前
Apache Doris + Lance:让多模态数据真正进入智能驾驶与具身智能的分析闭环互联网叫兽3 小时前
redis深入学习二