(二)SpringApplication.run()

在这里插入图片描述在这里插入图片描述

refresh方法详解

最终调用的是AbstractApplicationContext.refresh

即对容器的刷新:

1. this.prepareRefresh()

主要做的事情:
设置容器状态

注意两点:
容器是容器,BeanFactory是BeanFactory,
在Springboot启动过程中,以web类型举例:
先创建容器:context = this.createApplicationContext()
创建出的是AnnotationConfigServletWebServerApplicationContext类型的容器,return new AnnotationConfigServletWebServerApplicationContext()
然后执行三步:
    this.prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
    this.refreshContext(context);
    	重点:
    	(1)创建beanFactory,整个过程的主角是ConfigurableListableBeanFactory 
    	ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
    	(2)beanFactory预处理
    	this.prepareBeanFactory(beanFactory);
		this.postProcessBeanFactory(beanFactory);
		StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
        this.invokeBeanFactoryPostProcessors(beanFactory);
        this.registerBeanPostProcessors(beanFactory);
        beanPostProcess.end();
        this.initMessageSource();
        this.initApplicationEventMulticaster();
        this.onRefresh();
        	重点
        this.registerListeners();
        this.finishBeanFactoryInitialization(beanFactory);
        	重点:开启bean的加载过程
        this.finishRefresh();
    this.afterRefresh(context, applicationArguments);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值