从何处放入
AutoConfigurationImportSelector.selectImports
AbstractApplicationContext.refresh
AbstractApplicationContext.invokeBeanFactoryPostProcessors
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors
此处一个关键信息 只有BeanDefinitionRegistryPostProcessor的,才会有下面的逻辑,下面是这个类的注释
ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry
ConfigurationClassPostProcessor.processConfigBeanDefinitions
ConfigurationClassParser.parse
ConfigurationClassParser.process
ConfigurationClassParser.processGroupImports
ConfigurationClassParser.getImports
AutoConfigurationImportSelector.process
AutoConfigurationImportSelector.getAutoConfigurationEntry
从此方法获取到了默认需要加载的类,返回 AutoConfigurationEntry
AbstractApplicationContext.refresh
AbstractApplicationContext.invokeBeanFactoryPostProcessors
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors
ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry
ConfigurationClassPostProcessor.processConfigBeanDefinitions
ConfigurationClassBeanDefinitionReader.loadBeanDefinitions
ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass
ConfigurationClassBeanDefinitionReader.registerBeanDefinitionForImportedConfigurationClass
DefaultListableBeanFactory.registerBeanDefinition
至此,完成了第一步,放入了DefaultListableBeanFactory 的 beanDefinitionMap及beanDefinitionNames中
从何处取出并创建bean
AbstractApplicationContext.refresh
AbstractApplicationContext.finishBeanFactoryInitialization
DefaultListableBeanFactory.preInstantiateSingletons
接下来就是创建bean的流程了
AbstractBeanFactory.getBean
DefaultSingletonBeanRegistry.getSingleton
AbstractBeanFactory.getObject
AbstractAutowireCapableBeanFactory.createBean
AbstractAutowireCapableBeanFactory.doCreateBean
AbstractAutowireCapableBeanFactory.createBeanInstance
AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod
ConstructorResolver.instantiateUsingFactoryMethod
ConstructorResolver.instantiate
SimpleInstantiationStrategy.instantiate