从小白的角度看Spring核心流程概览(XML版)- 容器初始化第一章-概览

这一章先总体看一下refresh方法

	public void refresh() throws BeansException, IllegalStateException {
		//首先,获得锁,话说这名字取得够随意。在5.0.6版本之前,是没有这行代码的,哪位大佬知道作者为什么要这样写么?
        Object var1 = this.startupShutdownMonitor;
		// 加锁执行容器初始化操作
        synchronized(this.startupShutdownMonitor) {
			// Prepare this context for refreshing.
			// 准备此上下文刷新
            this.prepareRefresh();
			// Tell the subclass to refresh the internal bean factory.
			// 初始化beanFactory
            ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
			// Prepare the bean factory for use in this context.
			// 为beanFactory设置一些参数
            this.prepareBeanFactory(beanFactory);
            try {
				// Allows post-processing of the bean factory in context subclasses.
				// 注册一些postProcessBeanFactory
                this.postProcessBeanFactory(beanFactory);
				// Invoke factory processors registered as beans in the context.
				// 执行postProcessBeanFactory
                this.invokeBeanFactoryPostProcessors(beanFactory);
				// Register bean processors that intercept bean creation.
				// 注册一些BeanPostProcessors
                this.registerBeanPostProcessors(beanFactory);
				// Initialize message source for this context.
				// 初始化MessageSource
                this.initMessageSource();
				// Initialize event multicaster for this context.
				// 初始化spring事件派发器
                this.initApplicationEventMulticaster();
				// Initialize other special beans in specific context subclasses.
				// 执行子类的一些onRefresh方法,如果有的话
                this.onRefresh();
				// Check for listener beans and register them.
				// 注册监听器
                this.registerListeners();
				// Instantiate all remaining (non-lazy-init) singletons.
				// 实例化剩余的非懒加载的bean
                this.finishBeanFactoryInitialization(beanFactory);
				// Last step: publish corresponding event.
				// 执行事件
                this.finishRefresh();
            } catch (BeansException var9) {
                if(this.logger.isWarnEnabled()) {
                    this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var9);
                }
				// Destroy already created singletons to avoid dangling resources.
				// 销毁bean,有兴趣的自己看看
                this.destroyBeans();
				// Reset 'active' flag.
                this.cancelRefresh(var9);
                throw var9;
            } finally {
				// Reset common introspection caches in Spring's core, since we
				// might not ever need metadata for singleton beans anymore...
				// 清除一些缓存,有兴趣的自己看看
                t1his.resetCommonCaches();
            }
1
        }

	

##总体流程就是这样啦,下一章开始就是具体每个步骤啦,拜拜~

转载于:https://my.oschina.net/u/3367603/blog/2207244

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值