|
@@ -5,6 +5,7 @@
|
|
|
|
|
|
package cn.com.qmth.framework.config.center.utils;
|
|
|
|
|
|
+import cn.com.qmth.framework.config.center.core.ConfigConstants;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -49,7 +50,7 @@ public class PropertyUtils {
|
|
|
curProperties.load(br);
|
|
|
|
|
|
// 合并配置项(后面的配置文件内容优先级高于前面的!!!)
|
|
|
- properties.putAll(curProperties);
|
|
|
+ mergeProperties(properties, curProperties);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new RuntimeException(e);
|
|
@@ -65,6 +66,31 @@ public class PropertyUtils {
|
|
|
return properties;
|
|
|
}
|
|
|
|
|
|
+ private static void mergeProperties(Properties allProperties, Properties curProperties) {
|
|
|
+ if (allProperties.isEmpty()) {
|
|
|
+ allProperties.putAll(curProperties);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<Object, Object> property : curProperties.entrySet()) {
|
|
|
+ // 处理“KEY前缀”情况
|
|
|
+ String key = String.valueOf(property.getKey());
|
|
|
+ if (key.startsWith(ConfigConstants.SECRET_PROPERTY_PREFIX)) {
|
|
|
+ key = key.substring(ConfigConstants.SECRET_PROPERTY_PREFIX.length());
|
|
|
+ if (allProperties.containsKey(key)) {
|
|
|
+ allProperties.remove(key);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ key = ConfigConstants.SECRET_PROPERTY_PREFIX + key;
|
|
|
+ if (allProperties.containsKey(key)) {
|
|
|
+ allProperties.remove(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ allProperties.put(property.getKey(), property.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取配置文件内容
|
|
|
*/
|