除了注解等方式(参考: 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;
}
最新评论
喵影视TV,目前,最好用的吧,没有广告
已经死了这个app
大哥 求求
一个人用就够,多人钱包伤不起啊