Bean创建过程
实例化(反射创建实例)
初始化
(
给属性赋值:populateBean(beanName, mbd, instanceWrapper);
如果实现了BeanNameAware接口:执行((BeanNameAware) bean).setBeanName(beanName);
如果实现了BeanClassLoaderAware接口:执行((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);
如果实现了BeanFactoryAware接口:((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
找到所有BeanPostProcessor,逐个执行processor.postProcessBeforeInitialization(result, beanName);
wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
processor.postProcessBeforeInitialization(result, beanName);
如果实现了InitializingBean,执行((InitializingBean) bean).afterPropertiesSet();
invokeInitMethods(beanName, wrappedBean, mbd);
如果配置了init-method,执行配置的init-method
invokeCustomInitMethod(beanName, bean, mbd);
找到所有BeanPostProcessor,逐个执行processor.postProcessAfterInitialization(result, beanName);
wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
processor.postProcessAfterInitialization(result, beanName);
如果是单实例BEAN,添加到singletonObjects中
if (newSingleton) {
addSingleton(beanName, singletonObject);
}
如果是销毁Bean,调用destory-method配置的方法
)