springboot实战原理分析笔记(八)-springboot 运行流程

springboot 运行方法:
1.实例化SpringApplication对象,然后调用run方法。
运行流程:

	       1.判断是否是web环境
	       2.加载所有classpath下面的META-INF/spring.factories 的 ApplicationContextInitializer类
	       3.加载所有classpath下面的META-INF/spring.factories 的ApplicationListener类
	       4.指断main方法所在的类
           5.开始执行run方法
	       6.设置  java.awt.headless系统变量 System.setProperty("java.awt.headless", System.getProperty("java.awt.headless", Boolean.toString(this.headless)));	
	       7.加载所有classpath下面的META-INF/spring.factories 的SpringApplicationListener类(主要再不同得时间点,发送事件通知)	
	       8.执行所有SpringApplicationListener的start方法
	       9.实例化ApplicationArguments
	       10.创建Environment,根据不同的环境创建不同的Environment
           11.配置 Environment,主要把mian方法参数配置到Environment
                              this.configureEnvironment(environment, applicationArguments.getSourceArgs());
           12.执行所有SpringApplicationRunListeners的environmentPrepared方法	
	       13.	如果不是web环境,但是是web的environment,则把这个web得environment,转换成StandardEnvironment
           14.Banner打印环境 environment
           15初始化ApplicationContext,如果是web环境则初始化org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext ,否则org.springframework.context.annotation.AnnotationConfigApplicationContext 
	      16	.如果beanNameGenerator不为空,就把beanNameGenerator注入到spring容器(主要是一些方法的回调      , 比如我们通过app.setBeanNameGenerator();设置)
          17.回调所有的ApplicationContextInitializer方法
          18.执行所有SpringApplicationRunListeners的contextPrepared方法
	      19.一次方springr容器注入ApplicationArguments、Banner
           20.加载所有的源到context
	       21.执行所有SpringApplicationRunListeners的contextLoaded方法
           22.执行context的refresh方法,并且调用context得registerShutdownHook方法,到这里spring容器已经初始化完了
           23回调,获取容器中所有的ApplicationRunner、CommandLineRunner接口,然后排序
	      24.执行所有SpringApplicationRunListeners的finished方法

2.直接调用SpringApplication静态run方法。

       这一种方法,其实是将第一种方法封装。
       public static ConfigurableApplicationContext run(Object[] sources, String[] args) {
            return (new SpringApplication(sources)).run(args);
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值