上面一节简单的介绍了InstantiationAwareBeanPostProcessor可以在bean的实例化之前,调用回调的接口-postProcessorBeforInstantiation方法打断spring bean的默认实现。那本节简单的看下spring bean的默认实例化方法。
回到createBean(String beanName,RootBeanDefinition mbd,Objec[] args)方法。
/**
* Central method of this class: creates a bean instance,
* populates the bean instance, applies post-processors, etc.
* @see #doCreateBean
*/
@Override
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
throws BeanCreationException {
RootBeanDefinition mbdToUse = mbd;
//beanClass : String -> Class
Class<?> resolvedClass = resolveBeanClass(mbd, beanName);
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) {
mbdToUse = new RootBeanDefinition(mbd);
mbdTo