首页 > 编程语言 >Spring源码解析

Spring源码解析

时间:2023-01-28 18:25:28浏览次数:46  
标签:初始化 beanFactory Spring refresh 源码 var10 context 解析

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(); } } }

 

标签:初始化,beanFactory,Spring,refresh,源码,var10,context,解析
From: https://www.cnblogs.com/zhougongjin/p/17071049.html

相关文章