除了注解等方式(参考: Spring Boot获取yml文件配置注入Map/List/String等类型 ),还有一种直接读取的实现:
public static Object readProperties(String key) {
Object propertyValue = null;
Resource resource = new ClassPathResource("config/application-custom.yml");
Properties properties;
try {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(resource);
properties = yamlFactory.getObject();
propertyValue = properties.get(key);
} catch (Exception e) {
e.printStackTrace();
}
return propertyValue;
}

i软糖


最新评论
宝藏网站,差点找不回来了,之前我收藏的发布页打不开了。。。
谢谢您可以
视频资源很全好用,安装后提示更新,安装包站长可以更新一下。
哪个国家成功率高一点?换了十几个了