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

浙公网安备 33010602011771号