引用Abstract
ApplicationContext.refresh->finishBeanFactoryInitialization->beanFactory.preInstantiateSingletons()->getBean->doGetBean->getSingleton->singletonFactory.getObject()->createBean->doCreateBean->initializeBean
1. initializeBean的时候调用invokeAwareMethods(beanName, bean);(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(String, Object, RootBeanDefinition))
这时会:
1.1 调用BeanNameAware的setBeanName(beanName)方法
1.2 调用BeanClassLoaderAwarere的setBeanClassLoader(getBeanClassLoader())方法
1.3 调用BeanFactoryAware的setBeanFactory(AbstractAutowireCapableBeanFactory(AbstractAutowireCapableBeanFactory.this)方法
2 initializeBean的时候调用applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName),获取BeanPostProcessors,然后遍历调用每个posetProcessor的postProcessBeforeInitialization方法;org.springframework.context.support.ApplicationContextAwareProcessor的postProcessBeforeInitialization(Object, String)方法会执行invokeAwareInterfaces(bean)
这时会:
2.1 调用EnvironmentAware的setEnvironment(this.applicationContext.getEnvironment())方法
2.2 调用EmbeddedValueResolverAware的setEmbeddedValueResolver(new EmbeddedValueResolver(this.applicationContext.getBeanFactory())方法
2.3 调用ResourceLoaderAware的setResourceLoader(this.applicationContext)方法
2.4 调用ApplicationEventPublisherAware的setApplicationEventPublisher(this.applicationContext)方法
2.5 调用MessageSourceAware的setMessageSource(this.applicationContext)方法
2.6 调用ApplicationContextAware的setApplicationContext(this.applicationContext)方法
org.springframework.web.context.support.ServletContextAwareProcessor的postProcessBeforeInitialization(Object, String)中会完成:
2.7 调用ServletContextAware的setServletContext(getServletContext())方法
2.8 调用ServletConfigAware的setServletConfig(getServletConfig())方法
- class='magplus' title='点击查看原始大小图片' />
- 大小: 32.7 KB