/**
* 读取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
相关推荐
纆兰2 小时前
MySQL的多表查询七夜zippoe2 小时前
Nexent 模型配置:4 字段与 9 个槽位进击的荆棘2 小时前
MySQL——表的操作nice_lcj5204 小时前
MySQL 慢查询与 EXPLAIN:怎么定位、怎么优化OceanRoy14 小时前
数据库表的设计Pniubi15 小时前
怎么排查慢SQL,怎么解决?Decay__19 小时前
VMware 安装 SQL Server 双节点 AlwaysOn 可用性组教程 —— WSFC、AG 与侦听器完整部署(系列核心篇)茶栀(*´I`*)19 小时前
SQL 性能分析:从慢查询日志到执行计划的完整定位方法艺杯羹20 小时前
1Panel 装好后 ufw 仍是 inactive:一次服务器安全盲区复盘code2cat21 小时前
【随笔】MCP工具重试:任务已经创建,响应丢了怎么办