容器启动的收尾工作
1. 前言
写到这一章,我自己都有一种轻松的感觉,Spring容器到这里已经基本启动完成,容器已经构建完成,剩下的工作就是打扫战场了,比如清理资源加载器的缓存、初始化BeanFacotry的生命周期管理器、发布对应的容器Refresh事件等。这个阶段是Spring容器启动的最后一步,如下图中的红色方框部分所示。
/**
* Finish the refresh of this context, invoking the LifecycleProcessor's
* onRefresh() method and publishing the
*/
@SuppressWarnings("deprecation")
protected void finishRefresh() {
// Clear context-level resource caches (such as ASM metadata from scanning).
clearResourceCaches();
// Initialize lifecycle processor for this context.
initLifecycleProcessor();
// Propagate refresh to lifecycle processor first.
getLifecycleProcessor().onRefresh();
// Publish the final event.
publishEvent(new ContextRefreshedEvent(this