Spring源码解析

复制代码
public void refresh() throws BeansException, IllegalStateException {
        synchronized(this.startupShutdownMonitor) {
            StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
       // 初始化(记录容器开始时间、初始化一些集合)
this.prepareRefresh();
       // 创建beanFactory,旧
beanFactory存在就会销毁
       // XmlBeanDefinitionReader 读配置,加载配置到bean工厂
            ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
       //给beanFactory设置一些属性值
this.prepareBeanFactory(beanFactory); try {
          //留给子类拓展使用
this.postProcessBeanFactory(beanFactory); StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
          //实例化,并调用所有已注册的beanFactoryPostProcessor
this.invokeBeanFactoryPostProcessors(beanFactory); this.registerBeanPostProcessors(beanFactory); beanPostProcess.end();
          //初始化一些消息源
this.initMessageSource();
          //初始化时间多播器
this.initApplicationEventMulticaster(); this.onRefresh();
          //注册监听器
this.registerListeners();
          //初始化所有剩余实例
this.finishBeanFactoryInitialization(beanFactory);
          //清理缓存,发布事件等
this.finishRefresh(); } catch (BeansException var10) { if (this.logger.isWarnEnabled()) { this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var10); } this.destroyBeans(); this.cancelRefresh(var10); throw var10; } finally { this.resetCommonCaches(); contextRefresh.end(); } } }
复制代码

 

posted on   周公  阅读(9)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示