springBoot启动流程

1.启动类里面调用SpringApplication.run(xxx.class,args)方法

2.在SpringApplicaiton的run方法中有两个步骤,首先建立SpringApplicaiton对象,而后再调用run方法。
3.在SpringApplicaiton构造器中调用initialize(sources)方法。
4.initialize方法中,
a.将sources转换成list加到this.sources属性中
b.判断是否为web环境(在类路径下是否能够加载到Servlet和ConfigurableWebApplicationContext)
c.加载Initializers(经过META-INF/spring.factories中键为ApplicationContextInitializer的配置进行加载),dubug发现一共
加载了6个initializer(spring-boot-1.5.10.RELEASE.jar中4个,spring-boot-autoconfigure-1.5.10.RELEASE.jar中2个)
d.加载ApplicationListener(也是经过META-INF/spring.factories),debug发现共加载了10个
e.经过寻找main方法找到启动主类。
5.run方法中
a.StopWatch主要是监控启动过程,统计启动时间,检测应用是否已经启动或者中止。
b.加载SpringApplicationRunListener(也是经过META-INF/spring.factories),默认加载的是EventPublishingRunListener
c.调用RunListener.starting()方法。
d.根据args建立应用参数解析器ApplicationArguments;
e.准备环境变量:获取环境变量environment,将应用参数放入到环境变量持有对象中,监听器监听环境变量对象的变化(listener.environmentPrepared)
f.打印Banner信息(SpringBootBanner)
g.建立SpringBoot的应用上下文(AnnotationConfigEmbeddedWebApplicationContext)
h.prepareContext上下文以前的准备
i.refreshContext刷新上下文
j.afterRefresh(ApplicationRunner,CommandLineRunner接口实现类的启动)
k.返回上下文对象
相关文章
相关标签/搜索