乐趣区

关于springboot:Spring-Boot-如何处理Autowired二

Spring Boot 如何解决 @Autowired(一)
这篇小文可知 AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues() 最终执行对 @Autowired 的属性实例进行织入;而后以 DefaultListableBeanFactory.resolveDependency()->DefaultListableBeanFactory.doResolveDependency()->DependencyDescriptor.resolveCandidate()->beanFactory.getBean() 的链条进行创立 field bean 实例:

public Object resolveDependency(){
    // 省略其余 code
    {Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(descriptor, requestingBeanName);
            if (result == null) {result = doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
            }
            return result;
        }
}

public Object resolveCandidate(String beanName, Class<?> requiredType, BeanFactory beanFactory)
            throws BeansException {return beanFactory.getBean(beanName);
    }

当初是不是恍然大悟了?整个调用链路就清晰起来了~,原本有点懒,就不总结了,总结就交给读者敌人了,欢送留言加友探讨~

退出移动版