AbstractBeanDefinition

字段

在这里插入图片描述
在这里插入图片描述

factoryBeanName

在这里插入图片描述

factoryMethodName

在这里插入图片描述

methodOverrides

在这里插入图片描述

propertyValues 属性 (从yaml或者properties中读取)

在这里插入图片描述

方法

setBeanClass
书接上文 要设置setBeanClass了

AnnotatedGenericBeanDefinition的构造方法

这里使用到了父类AbstractBeanDefinition的setBean方法
在这里插入图片描述

 public void setBeanClass(@Nullable Class<?> beanClass) {
        this.beanClass = beanClass;
    }

在这里插入图片描述
beanClass在AbstractBeanDefinition是私有字段。

当一个类继承于另一个类,子类中没有父类的方法时。用子类的对象调用方法时,会首先在子类中查找,如果子类中没有改方法,再到父类中查找。当一个方法只在父类中定义时,调用该方法时会使用父类中的属性。

hasBeanClass()
public boolean hasBeanClass() {
        return this.beanClass instanceof Class;
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

prepareMethodOverrides

在这里插入图片描述

overrideFrom

在之前的实例中出现这样一个现象合并BeanDefinition
child中明明并没有{“age”,“18”}这个PropertyValues,最终却呈现处理了,为什么?
在这里插入图片描述
首先看一下在执行方法之前的该RootBeanDefinition
在这里插入图片描述

我们都知道这时的BeanDefinition还只是父BeanDefinition,也就是RootBean所对应的BeanDefinition,ChildBeanDefinition还没有更新进去。
在这里插入图片描述

这一步的更新操作位置还是比较容易找到的
在这里插入图片描述
addPropertyValues是具有替换逻辑的,会将others的BeanDefinition(子BeanDefinition)与当前BeanDefinition重叠的地方更新为others的Property。有了这样的BeanDefinition,最终的实例Bean当然也会额外打印age:18
在这里插入图片描述

  public void overrideFrom(BeanDefinition other) {
        if (StringUtils.hasLength(other.getBeanClassName())) {
            this.setBeanClassName(other.getBeanClassName());
        }

        if (StringUtils.hasLength(other.getScope())) {
            this.setScope(other.getScope());
        }

        this.setAbstract(other.isAbstract());
        if (StringUtils.hasLength(other.getFactoryBeanName())) {
            this.setFactoryBeanName(other.getFactoryBeanName());
        }

        if (StringUtils.hasLength(other.getFactoryMethodName())) {
            this.setFactoryMethodName(other.getFactoryMethodName());
        }

        this.setRole(other.getRole());
        this.setSource(other.getSource());
        this.copyAttributesFrom(other);
        if (other instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition otherAbd = (AbstractBeanDefinition)other;
            if (otherAbd.hasBeanClass()) {
                this.setBeanClass(otherAbd.getBeanClass());
            }

            if (otherAbd.hasConstructorArgumentValues()) {
                this.getConstructorArgumentValues().addArgumentValues(other.getConstructorArgumentValues());
            }

            if (otherAbd.hasPropertyValues()) {
                this.getPropertyValues().addPropertyValues(other.getPropertyValues());
            }

            if (otherAbd.hasMethodOverrides()) {
                this.getMethodOverrides().addOverrides(otherAbd.getMethodOverrides());
            }

            Boolean lazyInit = otherAbd.getLazyInit();
            if (lazyInit != null) {
                this.setLazyInit(lazyInit);
            }

            this.setAutowireMode(otherAbd.getAutowireMode());
            this.setDependencyCheck(otherAbd.getDependencyCheck());
            this.setDependsOn(otherAbd.getDependsOn());
            this.setAutowireCandidate(otherAbd.isAutowireCandidate());
            this.setPrimary(otherAbd.isPrimary());
            this.copyQualifiersFrom(otherAbd);
            this.setInstanceSupplier(otherAbd.getInstanceSupplier());
            this.setNonPublicAccessAllowed(otherAbd.isNonPublicAccessAllowed());
            this.setLenientConstructorResolution(otherAbd.isLenientConstructorResolution());
            if (otherAbd.getInitMethodName() != null) {
                this.setInitMethodName(otherAbd.getInitMethodName());
                this.setEnforceInitMethod(otherAbd.isEnforceInitMethod());
            }

            if (otherAbd.getDestroyMethodName() != null) {
                this.setDestroyMethodName(otherAbd.getDestroyMethodName());
                this.setEnforceDestroyMethod(otherAbd.isEnforceDestroyMethod());
            }

            this.setSynthetic(otherAbd.isSynthetic());
            this.setResource(otherAbd.getResource());
        } else {
            this.getConstructorArgumentValues().addArgumentValues(other.getConstructorArgumentValues());
            this.getPropertyValues().addPropertyValues(other.getPropertyValues());
            this.setLazyInit(other.isLazyInit());
            this.setResourceDescription(other.getResourceDescription());
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值