springboot不用注解的方式读取properties或者yml文件
properties
public static String getResourceValue(String keyName) {
try {
Resource resource = new ClassPathResource("filePath.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
String property = props.getProperty(keyName);
if(!Tools.isEmpty(property)){
return new String(property.getBytes("ISO-8859-1"), "utf-8");
}
return "";
} catch (Exception e) {
return "";
}
}
yml
YamlPropertiesFactoryBean factoryBean = new YamlPropertiesFactoryBean();
Resource resource = new ClassPathResource("application.yml");
factoryBean.setResources(resource);
Properties props = factoryBean.getObject();
props.getProperty("redis.port");