一、方法功能概述
// 最后一步,完成刷新
finishRefresh();最后一步,完成刷新
清理缓存资源
初始化lifecycleProcessor,默认是DefaultLifecycleProcessor
触发DefaultLifecycleProcessor的onRefresh方法
发布事件ContextRefreshedEvent
注册ApplicationContext到LiveBeansView内部的applicationContexts中
二、整体代码展示
//AbstractApplicationContext
/**
* Finish the refresh of this context, invoking the LifecycleProcessor's
* onRefresh() method and publishing the
* {@link org.springframework.context.event.ContextRefreshedEvent}.
* 完成此上下文的刷新,调用LifecycleProcessor的onRefresh方法并发布事件ContextRefreshedEvent
*/
protected void finishRefresh() {
// 清理缓存资源
clearResourceCaches();
// 初始化lifecycleProcessor,默认是DefaultLifecycleProcessor
initLifecycleProcessor();
// 触发DefaultLifecycleProcessor的onRefresh方法
getLifecycleProcessor().onRefresh();
// 发布事件ContextRefreshedEvent
publishEvent(new ContextRefreshedEvent(this));
// 注册ApplicationContext到LiveBeansView内部的applicationContexts中
LiveBeansView.registerApplicationContext(this);
}

该文详细介绍了Spring应用上下文在刷新过程中的关键步骤,包括清理缓存、初始化LifecycleProcessor、调用onRefresh方法、发布ContextRefreshedEvent事件以及将ApplicationContext注册到LiveBeansView中。
2762

被折叠的 条评论
为什么被折叠?



