读取resources目录下的配置文件

 public static Map<String,String> getProxyConfig(){
        Map map = null;
        Yaml yaml = new Yaml();
        Resource resource = new DefaultResourceLoader().getResource("classpath:application-proxyConfig.yml");
        try {
            InputStream inputStream = resource.getInputStream();
            map = (Map) yaml.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("proxy配置》"+map.toString());
        return map;
    }

new Yaml()要引入包

<dependency>
    <groupId>org.yaml</groupId>
    <artifactId>snakeyaml</artifactId>
</dependency>

 

posted on 2019-12-12 16:01  JAVA-ROAD  阅读(2004)  评论(0)    收藏  举报

导航