YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean(); yamlMapFactoryBean.setResources(new ClassPathResource("application.yml")); yamlMapFactoryBean.afterPropertiesSet(); Map<String, Object> object = yamlMapFactoryBean.getObject(); Object nameUrl = object.get("pnameUrl");
上面的这个方法可以将yml文件解析成map格式
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean(); yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml")); yamlPropertiesFactoryBean.afterPropertiesSet(); Properties object = yamlPropertiesFactoryBean.getObject(); Object nameUrl = object.get("pnameUrl");
这种方式将yml文件解析成(xxx.xxx.xxx)形式
这种方法是spring自带的,非常好用的可以获取配置文件的信息