Dependency injection getObjectForBeanInstance method in spring source code

    protected Object getObjectForBeanInstance(
            Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) {

        // Don"t let calling code try to dereference the factory if the bean isn"t a factory.
        if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) {
            throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
        }

        // Now we have the bean instance, which may be a normal bean or a FactoryBean.
        // If it"s a FactoryBean, we use it to create a bean instance, unless the
        // caller actually wants a reference to the factory.
        if (!(beanInstance instanceof FactoryBean) || BeanFactoryUtils.isFactoryDereference(name)) {
            return beanInstance;
        }

        //BeanBean
        //BeanBean
        Object object = null;
        if (mbd == null) {
            //BeanBean
            object = getCachedObjectForFactoryBean(beanName);
        }
        //BeanBean
        if (object == null) {
            // Return bean instance from factory.
            FactoryBean<?> factory = (FactoryBean<?>) beanInstance;
            // Caches object obtained from FactoryBean if it is a singleton.
            //BeanBean
            if (mbd == null && containsBeanDefinition(beanName)) {
                //Bean
                mbd = getMergedLocalBeanDefinition(beanName);
            }
            //BeanBean
            //BeanBean
            boolean synthetic = (mbd != null && mbd.isSynthetic());
            //FactoryBeanRegistrySupportgetObjectFromFactoryBean
            //BeanBean
            object = getObjectFromFactoryBean(factory, beanName, !synthetic);
        }
        return object;
    }
 if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) {
            throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
        }


if (!(beanInstance instanceof FactoryBean) || BeanFactoryUtils.isFactoryDereference(name)) {
    return beanInstance;
}

if
Nov.26,2021

/ *

     * FactoryBean
     *  isFactoryDereferencename name &
     */
    if (BeanFactoryUtils.isFactoryDereference(name)) {
        //NullBean  bean 
        if (beanInstance instanceof NullBean) {
            return beanInstance;
        }
        //FactoryBean
        if (!(beanInstance instanceof FactoryBean)) {
            throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
        }
    }

    // Now we have the bean instance, which may be a normal bean or a FactoryBean.
    // If it's a FactoryBean, we use it to create a bean instance, unless the
    // caller actually wants a reference to the factory.
    //  BeanbeanInstance bean  FactoryBean
    //  FactoryBean Bean
    if (!(beanInstance instanceof FactoryBean) || BeanFactoryUtils.isFactoryDereference(name)) {
        return beanInstance;
    }

the first if determines the case where both AB are true.
after the first if judgment, the second if determines A | | B is the case where An is true or B is true (if the first layer determines that AB is also true)
if the first if does not throw an exception, both An and B are not true. That is, either FactoryBean (An is not true)
, or beanName (B that begins with & is true), or neither is

.

analyze:

FactoryBean & bean
FactoryBean & FactoryBean
,if,FactoryBean&,FactoryBean

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b317fa-2bda6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b317fa-2bda6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?