/**
* 读取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
相关推荐
九零HTTP16 分钟前
10月21号-CSDN配菜-IP池的5个坑Data-Miner29 分钟前
需要做财务数据分析,有什么好用的工具?从准备到出报告的实操指南袋鼠云数栈1 小时前
让 SQL 解析不再重复造轮子:SqlParserX 正式开源这个DBA有点耶1 小时前
期货 CTP 系统 Oracle RAC 迁移国产库实战:读写分离架构设计与性能对标数据库安全2 小时前
AI数据访问安全 |如何控制AI访问权限,防止越权程序员老赵2 小时前
Docker 部署 Hue:轻松搭建数据库与数据仓库 SQL 查询平台这个DBA有点耶2 小时前
Redo Log循环写与checkpoint推进:长事务阻塞下的Checkpoint风暴完整链路jnrjian3 小时前
pg_waldump --key-file-name status 查看wal 产生的dbSelectDB技术团队3 小时前
Snowflake 的开源替代怎么选:能力对照、三条部署路径与迁移执行Elastic 中国社区官方博客3 小时前
告别繁琐控制台:Kabanos 如何将 MongoDB Compass 的易用性带入 Elasticsearch