一、properties文件读取
ClassPathResource classPathResource = new ClassPathResource("application.properties");
boolean exists = classPathResource.exists();
InputStream inputStream = classPathResource.getInputStream();
Properties properties = new Properties();
properties.load(inputStream);
String search = properties.getProperty("search.elasticsearch.uris");
String[] split = search.split(",");
Arrays.stream(split).forEach(System.out::println);
System.out.println(search);
properties.clear();
inputStream.close();
二、Yaml文件读取
YamlPropertiesFactoryBean yamlProFb = new YamlPropertiesFactoryBean ();
yamlProFb.setResources(new ClassPathResource("application2.yml"));
Properties object = yamlProFb.getObject();
String property = object.getProperty("search.elasticsearch.uris");