非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());
}
}

posted @ 2022-05-16 16:49  npe0  阅读(395)  评论(0)    收藏  举报