Spring IOC container startup process

       1. Add a lock to prevent the operation of starting or destroying the container during refresh.

synchronized (this.startupShutdownMonitor)

       2. Preparation work, record the start time of the container, mark the "started" state, and process the placeholders in the configuration file.

prepareRefresh();

       3. Initialize the BeanFactory, first create an instance of DefaultListableBeanFactory, then parse the configuration information into beanDefinition, and encapsulate the ConcurrentHashMap of beanName -> beanDefinition in the BeanFactory.

ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

       4. BeanFactory post processor processing.

prepareBeanFactory(beanFactory);

       5. Load and register Bean, add some special implementation classes of BeanFactoryPostProcessor or do something.

postProcessBeanFactory(beanFactory);

       6. Implementation and registration of BeanPostProcessor.

invokeBeanFactoryPostProcessors(beanFactory);    registerBeanPostProcessors(beanFactory);

       7. Initialize and process the message source of the context.

initMessageSource();

       8. The hook method initializes the special bean.

onRefresh();

       9. Register the event listener, check the listening Beans and register these Beans with the container.

 registerListeners();

       10. Initialize all singleton beans, get them through getBean() of AbstractBeanFactory according to different types of Beans, and then createBean(). Create bean instance (parameter encapsulation)

finishBeanFactoryInitialization(beanFactory);

       11. Publish the broadcast event and end the refresh process.

finishRefresh();

 

Reference: Spring IOC container source code analysis

 

Guess you like

Origin blog.csdn.net/Anenan/article/details/115064889