去字节面试,直接让人出门左拐:Bean 生命周期都不知道!
spring启动创建bean流程
下面就接上了
bean生命周期
doGetBean
Object sharedInstance = this.getSingleton(beanName);
sharedInstance = this.getSingleton(beanName, new ObjectFactory<Object>() {public Object getObject() throws BeansException {
beanInstance = this.doCreateBean(beanName, mbdToUse, args);
主要步骤
getBean->doGetBean->getSingleton这个逻辑,我们着重关注一下getSingleton方法的实现
属性赋值
this.populateBean(beanName, mbd, instanceWrapper);
初始化 exposedObject = this.initializeBean(beanName, exposedObject, mbd);
Object earlySingletonReference = this.getSingleton(beanName, false);