atguigu的springboot补充---spring3(2)---SpringBoot_原理

四个:

ApplicationContextInitializer
SpringApplicationRunListener
ApplicationRunner
CommandLineRunner

这几个核心的接口。

代码:

第一步:启动分为2步

第二步:

第三步:

//保存主配置类

// 判断是不是web应用

// 一直点

看下这个方法

找到所有的ApplicationInizalize先保存起来。

在自动配置包里面,找ApplicationContextInitializer保存起来。

先把Initializer保存起来至于什么时候调用是不一定的。

第四步:

第五步:决定哪个是主程序

到这里对象就创建出来了。

------------------------68---------------------------------

第六步:运行程序

public ConfigurableApplicationContext run(String... args) {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
        // 1.声明这个容器 开始是空的
		ConfigurableApplicationContext context = null;
		FailureAnalyzers analyzers = null;
		configureHeadlessProperty();
        // 2.获取监听器
		SpringApplicationRunListeners listeners = getRunListeners(args);
        // 3.starting方法回调下
		listeners.starting();
		try {
            // 4.封装命令行参数
			ApplicationArguments applicationArguments = new DefaultApplicationArguments(
					args);
            // 5.准备环境
			ConfigurableEnvironment environment = prepareEnvironment(listeners,
					applicationArguments);
            // 6.打印banner图标
			Banner printedBanner = printBanner(environment);
            // 7.创建ioc容器
			context = createApplicationContext();
			analyzers = new FailureAnalyzers(context);
            // 8.准备上下文
			prepareContext(context, environment, listeners, applicationArguments,
					printedBanner);
            // 9.刷新ioc容器
			refreshContext(context);
            // 10.刷新之后
			afterRefresh(context, applicationArguments);
            // 11.回调finish方法
			listeners.finished(context, null);
			stopWatch.stop();
			if (this.logStartupInfo) {
				new StartupInfoLogger(this.mainApplicationClass)
						.logStarted(getApplicationLog(), stopWatch);
			}
            // 12.启动完成返回ioc容器
			return context;
		}
		catch (Throwable ex) {
			handleRunFailure(context, listeners, analyzers, ex);
			throw new IllegalStateException(ex);
		}
	}

2.进入也是获取监听器,和之前的一样。

3.starting下,回调starting方法:

5.准备环境

调用listener的这个方法。

7.创建ioc容器ApplicationContext

是创建web的还是普通的?

8.准备上下文

进去:

获取所有的Inizializer调用initialize方法,注意就是之前保存的那些。

继续:

再走:

回调。

9.刷新ioc容器,就是经典的一大段了

10.

两个重要的方法:

11.回调

总结:

------------------------69---------------------------------

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值