资讯

展开

SpringBoot获取配置文件全部配置信息

作者:快盘下载 人气:

    ;Autowired
    private StandardServletEnvironment standardServletEnvironment;

        HashMap<String,Object> hashMap = new HashMap<>();
        MutablePropertySources propertySources = standardServletEnvironment.getPropertySources();
        Iterator<PropertySource<?>> iterator = propertySources.iterator();
        while(iterator.hasNext()) {
            PropertySource<?> next = iterator.next();    
            if(next instanceof OriginTrackedMapPropertySource) {
                OriginTrackedMapPropertySource originTrackedMapPropertySource=(OriginTrackedMapPropertySource) next;
                Map<String, Object> source = originTrackedMapPropertySource.getSource();
                for (Map.Entry<String,Object> entry:source.entrySet()){
                    hashMap.put(entry.getKey(), entry.getValue().toString());
                }
            }
        }

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!