wujimin commented on a change in pull request #745: [SCB-636] change config
mapping machanism
URL:
https://github.com/apache/incubator-servicecomb-java-chassis/pull/745#discussion_r193599910
##########
File path:
foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigMapping.java
##########
@@ -17,20 +17,43 @@
package org.apache.servicecomb.config;
-import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Created by on 2017/1/5.
*/
public final class ConfigMapping {
private static Map<String, Object> configMap = null;
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ConfigMapping.class);
+
static {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- InputStream is = loader.getResourceAsStream("mapping.yaml");
- configMap = YAMLUtil.yaml2Properties(is);
+ List<URL> urlList = new ArrayList<>();
+ configMap = new HashMap<String, Object>();
+ Enumeration<URL> urls;
+ try {
+ urls = loader.getResources("mapping.yaml");
+ while (urls.hasMoreElements()) {
+ urlList.add(urls.nextElement());
+ }
+ for (URL url : urlList) {
+ configMap.putAll(YAMLUtil.yaml2Properties(url.openStream()));
Review comment:
"snake yaml's demo and document don't require to close the stream"
it's not a good idea to work in this way.
1.YAMLUtil.yaml2Properties is our code
2.if you are not sure if "yaml.loadAll" will close stream, it's better to
read the source code, not guess
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services