/**
* 读取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
相关推荐
ttthe_MOon几秒前
Redis Cluster集群模式和各种常见问题小鸡脚来咯3 分钟前
MySQL InnoDB内存结构,增删改查时怎么运行的杨了个杨898213 分钟前
PostgreSQL(pgSQL)常用操作蝈蝈(GuoGuo)16 分钟前
SQL Server 中指定范围分页取数详解慕白Lee20 分钟前
【PostgreSQL】日常总结sc.溯琛25 分钟前
MySQL 视图实战:简化查询与数据安全管控指南风月歌27 分钟前
小程序项目之校园二手交易平台小程序源代码(源码+文档)西格电力科技33 分钟前
绿电直连架构适配技术的发展趋势计算机毕设VX:Fegn089538 分钟前
计算机毕业设计|基于springboot + vue汽车销售系统(源码+数据库+文档)@小白向前冲1 小时前
数据库创表(方便自己查看)