读取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>
以上内容原创来自每特学院,每特学员学习并整理!
给学院打波广告:
http://www.mayikt.com/
浙公网安备 33010602011771号