I’ll talk to you again, hey hey~
In the run () method startup process described in the previous section, there is a line of code:
refreshContext(context);
This line of code is today’s hero – it completes the loading of the bean. Its implementation is in the refresh() method of abstractapplicationcontext class, with the following code:
@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
//Container status setting, initialization attribute setting, verification mandatory attribute
prepareRefresh();
//Get beanfactory
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
//Set some properties of beanfactory, add post processor, register the default environment beans
prepareBeanFactory(beanFactory);
try {
//Empty method, leave a hook for the subclass and inject it into postprocessors
postProcessBeanFactory(beanFactory);
StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
//Execute beanfactoryprocessor
invokeBeanFactoryPostProcessors(beanFactory);
//Beanpostprocessor registers into the container
registerBeanPostProcessors(beanFactory);
beanPostProcess.end();
//Initialize the message source for the container
initMessageSource();
//Register event broadcaster for container
initApplicationEventMulticaster();
//Empty method, leaving the subclass to register other beans
onRefresh();
//Register the event listener and dispatch the events that have not been handled before
registerListeners();
//Initialize the remaining single instance beans
finishBeanFactoryInitialization(beanFactory);
//Initialize the cycle processor and publish the container startup event
finishRefresh();
}
…………
finally {
//Clear cache
resetCommonCaches();
contextRefresh.end();
}
}
}
The above is the core process of spring container startup. In the next section, the focus comes~~