PropertiesUtils提醒信息优化

This commit is contained in:
thinkgem
2020-02-02 12:46:42 +08:00
parent 055befdb79
commit bf6940ae92

View File

@@ -105,18 +105,19 @@ public class PropertiesUtils {
*/ */
public PropertiesUtils(String... configFiles) { public PropertiesUtils(String... configFiles) {
for (String location : configFiles) { for (String location : configFiles) {
try { Resource resource = ResourceUtils.getResource(location);
Resource resource = ResourceUtils.getResource(location); if (resource.exists()){
if (resource.exists()){ if (location.endsWith(".properties")){
if (location.endsWith(".properties")){ try (InputStreamReader is = new InputStreamReader(resource.getInputStream(), "UTF-8")){
try (InputStreamReader is = new InputStreamReader(resource.getInputStream(), "UTF-8")){ properties.load(is);
properties.load(is); configSet.add(location);
configSet.add(location); } catch (IOException e) {
} catch (IOException ex) { System.err.println("Load " + location + " failure.");
logger.error("Load " + location + " failure. ", ex); e.printStackTrace();
}
} }
else if (location.endsWith(".yml")){ }
else if (location.endsWith(".yml")){
try {
YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean();
bean.setResources(resource); bean.setResources(resource);
for (Map.Entry<Object,Object> entry : bean.getObject().entrySet()){ for (Map.Entry<Object,Object> entry : bean.getObject().entrySet()){
@@ -124,10 +125,11 @@ public class PropertiesUtils {
ObjectUtils.toString(entry.getValue())); ObjectUtils.toString(entry.getValue()));
} }
configSet.add(location); configSet.add(location);
} } catch (Exception e) {
} System.err.println("Load " + location + " failure.");
} catch (Exception e) { e.printStackTrace();
logger.error("Load " + location + " failure. ", e); }
}
} }
} }
properties.put("configFiles", StringUtils.join(configFiles, ",")); properties.put("configFiles", StringUtils.join(configFiles, ","));