SpringBoot启动流程
2021-09-19 16:02:44 8 举报
SpringBoot启动流程主要包括以下步骤:1. 加载配置文件,如application.properties或application.yml;2. 创建并初始化Spring容器;3. 扫描并加载所有可用的组件,包括bean定义、自动配置等;4. 根据条件注解和Profile配置,进行Bean的实例化和属性注入;5. 发布ContextRefreshedEvent事件,通知所有Bean已经准备就绪;6. 启动嵌入式Web服务器(如Tomcat);7. 处理所有的请求,并返回响应。整个过程中,SpringBoot通过自动化的配置和约定优于配置的原则,大大简化了项目的开发和部署。
作者其他创作
大纲/内容
ConfigurableApplicationContext context = null;\t\tCollection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
StopWatch stopWatch = new StopWatch();\t\tstopWatch.start();
Tomcat tomcat = new Tomcat();
loadSpringFactories(ClassLoader classLoader)
@EnableAutoConfiguration
initialize()
context.registerShutdownHook();
refreshContext(context);
ServletWebServerApplicationContext
Enumeration urls = classLoader.getResources(\"META-INF/spring.factories\");
createWebServer()
refresh(context);
this.onRefresh();
@AutoConfigurationPackage@Import(AutoConfigurationImportSelector.class)
getWebServer(ServletContextInitializer... initializers)
((AbstractApplicationContext) applicationContext).refresh();
Banner printedBanner = printBanner(environment);
listeners.running(context);
new SpringApplication(primarySources)
run
getTomcatWebServer(tomcat)
configureHeadlessProperty();\t\tSpringApplicationRunListeners listeners = getRunListeners(args);\t\tlisteners.starting();
selectImports(AnnotationMetadata annotationMetadata) // 方法
this.webServer = factory.getWebServer(getSelfInitializer());
TomcatServletWebServerFactory
refreshContext(ConfigurableApplicationContext context)
ConfigurableApplicationContext run(String... args)
@SpringBootApplication注解
AutoConfigurationImportSelector.class
0 条评论
下一页