AbstractApplicationContext#refresh()
@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing.
//准备刷新
prepareRefresh();
// Tell the subclass to refresh the internal bean factory.
//获取新的工厂
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// Prepare the bean factory for use in this context.
//准备工厂
prepareBeanFactory(beanFactory);
try {
// Allows post-processing of the bean factory in context subclasses.
// 后处理工厂 (调用子类)
postProcessBeanFactory(beanFactory);
// Invoke factory processors registered as beans in the context.
// 调用bean工厂的后置处理器们
invokeBeanFactoryPostProcessors(beanFactory);
// Register bean processors that intercept bean creation.
// 注册bean处理器们,用来拦截bean的创建
registerBeanPostProcessors(beanFactory);
// Initialize message source for this context.
//初始化-国际化i18n
initMessageSource();
// Initialize event multicaster for this context.
//初始化应用多路广播
initApplicationEventMulticaster();
// Initialize other special beans in specific context subclasses.
//初始化其他特殊的bean(调用子类)
onRefresh();
// Check for listener beans and register them.
// 校验和注册监听器
registerListeners();
// Instantiate all remaining (non-lazy-init) singletons.
// 完成工厂的初始化,实例化所有剩余的非延迟加载的单实例
finishBeanFactoryInitialization(beanFactory);
// Last step: publish corresponding event.
// 完成刷新
finishRefresh();
} catch (BeansException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Exception encountered during context initialization - " +
"cancelling refresh attempt: " + ex);
}// Destroy already created singletons to avoid dangling resources.
destroyBeans();// Reset 'active' flag.
cancelRefresh(ex);// Propagate exception to caller.
throw ex;
} finally {
// Reset common introspection caches in Spring's core, since we
// might not ever need metadata for singleton beans anymore...
resetCommonCaches();
}
}
}
AbstractApplicationContext#refresh()
最新推荐文章于 2024-05-12 15:46:58 发布