1 Star 0 Fork 156

whl595145999 / Spring-Analysis

forked from huifer / Code-Analysis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Spring-ManagedMap.md 1.34 KB
一键复制 编辑 原始数据 按行查看 历史

Spring ManagedMap

  • 类全路径: org.springframework.beans.factory.support.ManagedMap

  • 类图: ManagedMap.png

  • 对应标签 <map>

      <property name="someMap">
          <map>
              <entry key="an entry" value="just some string"/>
              <entry key ="a ref" value-ref="myDataSource"/>
          </map>
      </property>
    • 解析xml的处理方法: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseMapElement 这里不做具体展开

方法列表

merge

  • ManagedMap 作为Mergeable的实现类, 其操作的对象为LinkedHashMap, 想到合并可以联想到 LinkedHashMap#putAll => java.util.Map.putAll Spring 中也正是如此进行操作的. 详细代码如下
@Override
@SuppressWarnings("unchecked")
public Object merge(@Nullable Object parent) {
    if (!this.mergeEnabled) {
        throw new IllegalStateException("Not allowed to merge when the 'mergeEnabled' property is set to 'false'");
    }
    if (parent == null) {
        return this;
    }
    if (!(parent instanceof Map)) {
        throw new IllegalArgumentException("Cannot merge with object of type [" + parent.getClass() + "]");
    }
    Map<K, V> merged = new ManagedMap<>();
    merged.putAll((Map<K, V>) parent);
    merged.putAll(this);
    return merged;
}
Java
1
https://gitee.com/595145999/spring-analysis.git
git@gitee.com:595145999/spring-analysis.git
595145999
spring-analysis
Spring-Analysis
master

搜索帮助