其他分享
首页 > 其他分享> > 非Bean读取配置

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

}

标签:读取,public,配置,properties,isProd,Bean,static,Properties,String
来源: https://www.cnblogs.com/geekdc/p/16277523.html