63 Star 428 Fork 156

huifer/Code-Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
docs
beans
AbstractNestablePropertyAccessor
BeanDefinition
BeanInfoFactory
BeanMetadataElement
BeanReference
Mergeable
images
Readme.md
Spring-AliasDefinition.md
Spring-AutowireCandidateQualifier.md
Spring-BeanComponentDefinition.md
Spring-BeanDefinitionHolder.md
Spring-BeanMetadataAttribute.md
Spring-ConstructorArgumentValues.ValueHolder.md
Spring-DocumentDefaultsDefinition.md
Spring-ImportDefinition.md
Spring-ManagedList.md
Spring-ManagedMap.md
Spring-ManagedProperties.md
Spring-ManagedSet.md
Spring-MethodOverride.md
Spring-TypedStringValue.md
BeanWrapper
CachedIntrospectionResults
ComponentDefinition
ConfigurablePropertyAccessor
GenericTypeAwarePropertyDescriptor
Property
PropertyAccessor
Scope
factory
propertyEditor
register
core
env
other
utils
release
.gitattributes
.gitignore
CHANGELOG.MD
LICENSE
Notice
README.md
_coverpage.md
index.html
summary.md
todo.md
克隆/下载
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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pychfarm_admin/code-analysis.git
git@gitee.com:pychfarm_admin/code-analysis.git
pychfarm_admin
code-analysis
Code-Analysis
v0.0.15

搜索帮助