doCreateBean – populateBean

doCreateBean - populateBean

属性扫描完成之后, 就可以开始属性注入了.

代码块:

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean

boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&
        isSingletonCurrentlyInCreation(beanName));
if (earlySingletonExposure) {
    if (logger.isTraceEnabled()) {
        logger.trace("Eagerly caching bean "" + beanName +
                "" to allow for resolving potential circular references");
    }
    //这里创建了一个匿名的 ObjectFactory 实现类, 他是一个工厂, 可以用来获取对象
    //addSingletonFactory中, 将这个工厂放到 singletonFactories 中去了. singletonFactories 是spring的三级缓存
    addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));
}

// Initialize the bean instance.
Object exposedObject = bean;
try {
    //设置属性,非常重要
    populateBean(beanName, mbd, instanceWrapper);
    //执行后置处理器,aop就是在这里完成的处理
    exposedObject = initializeBean(beanName, exposedObject, mbd);
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » doCreateBean – populateBean