springBoot
2021-08-21 22:30:37 11 举报
springBoot启动流程
作者其他创作
大纲/内容
//读取项目的配置文件,并保存到environment中ConfigurableEnvironment environment
finishRefresh();
告诉子类刷新内部BeanFactoryobtainFreshBeanFactory()
ConfigurableApplicationContext
onRefresh();
getRunListeners(args)
getBean(beanName)
//调用BeanFactoryPostProcessor后置处理器,其中有一个后置处理器ConfigurationClassPostProcessor,它将由启动类开始,递归解析项目中配置的bean,将bean解析为BeanDefinition对象,放置到beanDefinitionMap中
refreshContext(context);
//启动web容器(tomcat容器)getLifecycleProcessor().onRefresh();
context = createApplicationContext();
new SpringApplication(primarySources)
ConfigurableApplicationContext run(String... args)
ConfigurationClassPostProcessor
//读取resources/META-INF/spring.factories配置文件中配置的SpringApplicationRunListener.class类型的事件发布器,由它发布的事件会被ApplicationListener监听到org.springframework.boot.SpringApplicationRunListener=\\org.springframework.boot.context.event.EventPublishingRunListener
SpringApplication
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
SpringApplicationRunListeners listeners = getRunListeners(args);
parser.parse(candidates);
new SpringApplication(primarySources).run(args);
//遍历beanDefinitionMap,实例并初始化单例Bean
我们的应用是WebApplicationType.SERVLET类型,创建的是AnnotationConfigServletWebServerApplicationContext类型的实例
finishBeanFactoryInitialization(beanFactory);
//创建web服务器,默认是tomcat容器createWebServer()
createApplicationContext()
invokeBeanFactoryPostProcessors(beanFactory);
ConfigurableListableBeanFactory
//推断应用的类型,一般是WebApplicationType.SERVLET类型this.webApplicationType = WebApplicationType.deduceFromClasspath();//读取resources/META-INF/spring.factories配置文件中配置的ApplicationContextInitializer.class类型的容器上下文初始化器setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));//读取resources/META-INF/spring.factories配置文件中配置的ApplicationListener.class类型的应用监听器setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
收藏
0 条评论
下一页