This is the 12th day of my participation in Gwen Challenge

The BeanFactory is the Spring IoC underlying container, and the ApplicationContext is its superset, so I’ll focus on the ApplicationContext here.

The entrance to the ApplicationContext lifecycle AbstractApplicationContext# refresh method

1. Application context startup preparation. AbstractApplicationContext# prepareRefresh start time startupDate status identification closed active (true) (false) initialization PropertSources – The initPropertySources validation Environment must initialize the collection of early Spring events

Create BeanFactory. AbstractApplicationContext# obtainFreshBeanFactory exists the BeanFactory, CreateBeanFactory createBeanFactory set BeanFactory id customizeBeanFactory Whether the BeanDefinition can be repeated, and whether the loadBeanDefinitions method can be loaned to load the BeanDefinition and assign the BeanFactory to the ApplicationContext

3. BeanFactory ready. AbstractApplicationContext# prepareBeanFactory set Bean BeanClassLoader expression processor add PropertyEditorRegistrar the implementation of the object ResourceEditorRegistrar Add BeanPostProcessor to override the Aware interface as the dependency injection interface to register the ResovlableDependency object: The BeanFactory, ResourceLoader, ApplicationEventPublisher, ApplicationContext registered ApplicationListenerDetector object LoadTimeWeaverAwareProcessor registered singleton object Environment, Java System Properties, OS Environment variables

4. BeanFactory post-processing. AbstractApplicationContext# postProcessBeanFactory, invokeBeanFactoryPostProcessors postProcessBeanFactory method by subclasses covered call PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, Set TempClassLoader LoadTimeWeaverAwareProcessor getBeanFactoryPostProcessors () method

5. Register BeanFactory with BeanPostProcessor. AbstractApplicationContext#registerBeanPostProcessors PostProcessorRegistrationDelegate.registerBeanPostProcessors(beanFactory, this); Register BeanPostProcessor Beans of the PriorityOrdered type Register BeanPostProcessor Beans of the Ordered type register normal BeanPostProcessor Beans (nonOrderedPostProcessors) registered MergedBeanDefinitionPostProcessor Beans (internalPostProcessors) registration ApplicationListenerDetector object

Initialize the built-in bean-messagesource. AbstractApplicationContext# initMessageSource if there is no messageSource bean, register the singleton beans if DelegatingMessageSource exist and need to set up level, to set up

7. Initialize the built-in bean-Spring broadcaster. AbstractApplicationContext# initApplicationEventMulticaster if there is no applicationEventMulticaster bean, Registered singleton bean SimpleApplicationEventMulticaster there is set to the current attributes

Spring application context refresh. AbstractApplicationContext# onRefresh to subclasses override

Spring event listener registration. AbstractApplicationContext# registerListeners add ApplicationListener object registration by adding the BeanFactory ApplicationListener Beans Broadcast early events

10. BeanFactory initialization is complete. AbstractApplicationContext# finishBeanFactoryInitialization if there is a set conversionService beans StringValueResolver lookup LoadTimeWeaverAware Bean BeanFactory empty tempClassLoader BeanFactory Unfrozen configuration BeanFactory initializes a non-delayed singleton Bean

Spring application context refresh is complete. AbstractApplicationContext# finishRefresh empty ResourceLoader cache object initialization LifeCycleProcessor call LifeCycleProcessor# onRefresh Method Publish context ContextRefreshedEvent has been refreshed event to MBeanServer hosted Live Beans 12, Spring application context launch. AbstractApplicationContext# start to find and start ContextStartedEvent LifeCycleProcessor release context has start events

Spring application stops below. AbstractApplicationContext# stop searching and start LifeCycleProcessor release context ContextStoppedEvent has stopped

The Spring application is closed below. AbstractApplicationContext# close status identification closed (true) active (false) Live Bean JMX revocation managed to find and release the context ContextClosedEvent closed events to shut down LifeCycleProcessor destroys all beans close BeanFactory onClose method callback to remove ShutdownHook early event handler