Springboot啟動(dòng)流程:
0.判斷springboot項(xiàng)目的屬性
在SpringApplication類中有一個(gè)私有變量: webApplicationType
該屬性決定了當(dāng)前springboot項(xiàng)目是否是一個(gè)web項(xiàng)目:
private WebApplicationType deduceWebApplicationType() {
if (ClassUtils.isPresent(REACTIVE_WEB_ENVIRONMENT_CLASS, null)
&& !ClassUtils.isPresent(MVC_WEB_ENVIRONMENT_CLASS, null)) {
return WebApplicationType.REACTIVE;
}
for (String className : WEB_ENVIRONMENT_CLASSES) {
if (!ClassUtils.isPresent(className, null)) {
return WebApplicationType.NONE;
}
}
return WebApplicationType.SERVLET;
}
1.加載ApplicationContextInitializer接口的實(shí)現(xiàn)類,具體的實(shí)現(xiàn)類在spring.factory中定義:
其中spring-boot-2.0.3.RELEASE.jar定義的有以下四個(gè):
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,
org.springframework.boot.context.ContextIdApplicationContextInitializer,
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
spring-boot-autoconfigure-2.0.3.RELEASE.jar定義的有以下兩個(gè):
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
在SpringApplication中使用反射實(shí)例化并緩存起來
2.加載ApplicationListener接口的實(shí)現(xiàn)類,具體實(shí)現(xiàn)類也是在spring.factory中定義:
其中spring-boot-2.0.3.RELEASE.jar定義的有以下九個(gè):
org.springframework.boot.ClearCachesApplicationListener,
org.springframework.boot.builder.ParentContextCloserApplicationListener,
org.springframework.boot.context.FileEncodingApplicationListener,
org.springframework.boot.context.config.AnsiOutputApplicationListener,
org.springframework.boot.context.config.ConfigFileApplicationListener,
org.springframework.boot.context.config.DelegatingApplicationListener,
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,
org.springframework.boot.context.logging.LoggingApplicationListener,
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
具體的工作流程參考此圖:
springboot啟動(dòng)流程圖