非Bean读取配置
public class WebConfigUtil {
public static final String YML_NAME = "application.yml";
private static Properties readProperties(String... confFile) {
final Properties properties = new Properties();
try {
for (String path : confFile) {
final ClassPathResource resource = new ClassPathResource(path);
properties.load(resource.getInputStream());
}
} catch (IOException e) {
}
return properties;
}
public static Properties readYamls(String... confFile) {
YamlPropertiesFactoryBean yamlMapFactoryBean = new YamlPropertiesFactoryBean();
for (String path : confFile) {
yamlMapFactoryBean.setResources(new ClassPathResource(path));
}
Properties properties = yamlMapFactoryBean.getObject();
return properties;
}
public static boolean isProd() {
Properties properties = readYamls(YML_NAME);
String isProd = properties.getProperty("spring.redis-sentinel.cluster.isProd");
return Boolean.valueOf(isProd);
}
public static void main(String[] args) {
System.out.println(isProd());
}
}
作者:null-npe 出处:https://www.cnblogs.com/npe 由于作者个人水平有限,如果文中有什么错误,欢迎指出。以免更多的人被误导。 |