资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

SpringBoot启动流程断点过程的示例分析

这篇文章主要介绍Spring Boot启动流程断点过程的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

成都创新互联公司是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,小程序制作,10多年建站对成都隧道混凝土搅拌车等多个方面,拥有丰富的网站运维经验。

启动入口

Spring Boot启动流程断点过程的示例分析

跟进run方法 : 一个用来使用默认的配置从特定的源运行SpringApplication的静态帮助类。

这个类有两个重载方法,另一个用来传入多个源。通常,单个参数方法是数组方法的一个特例

Spring Boot启动流程断点过程的示例分析

创建一个新的SpringApplication实例。这个应用程序上下文会从特定的源加载Beans,这个实例会在调用run方法之前被定制化。

Web应用程序类型的枚举:WebApplicationType,包含NONE(不是web应用),SERVLET(基于Servlet的web应用),REACTIVE(基于Reactive的web应用)

  • 直接jar包运行不使用web容器

  • 使用嵌入式的Servlet web容器

  • 使用反应式的web容器

Spring Boot启动流程断点过程的示例分析

setInitializers((Collection) getSpringFactoriesInstances(
  ApplicationContextInitializer.class));

用于创建和加载Spring工厂方法实例

Spring Boot启动流程断点过程的示例分析

Spring Boot启动流程断点过程的示例分析

Spring Boot启动流程断点过程的示例分析

Spring Boot启动流程断点过程的示例分析

4.运行SpringApplication的run方法

Spring Boot启动流程断点过程的示例分析

Java SPI在 Spring Boot中的应用

SpringBoot底层的自动化都是由这些SPI实现类来实现的:初始化,监听器,自动配置导入监听器,自动配置导入过滤器,自动配置,失败分析器,可用模板提供者

Spring Boot启动流程断点过程的示例分析

Spring Boot找到main方式的方式

通过抛异常的形式来获取堆栈信息,再获取启动类的信息。

Spring Boot启动流程断点过程的示例分析

以上都是new SpringBootApplication的过程,下面分析run方法

/**
* Run the Spring application, creating and refreshing a new
* {@link ApplicationContext}.
* 运行一个Spring应用,创建和刷新一个新的ApplicationContext
* @param args the application arguments (usually passed from a Java main method)
* 应用参数通过java main方法传递过来
* @return a running {@link ApplicationContext}
*/
public ConfigurableApplicationContext run(String... args) {
// 任务计时器工具,可同时计数多个任务
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//ApplicationContext是Spring的中心接口,为应用提供配置:1bean工厂2加载资源3注册的监听器发布事件4解析消息
ConfigurableApplicationContext context = null;
Collection exceptionReporters = new ArrayList<>();
//headless 模式:服务器端模式,表示系统没有键盘鼠标等前端应用
configureHeadlessProperty();
//监听器容器,对run方法各个阶段事件进行监听,观察者模式
SpringApplicationRunListeners listeners = getRunListeners(args);
//监听相应的事件,SpringApplicationEvent下的一个实现
listeners.starting();
try {
//提供了对于运行SpringApplication参数的访问
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
//环境配置:是servlet,reactive或者java应用环境,触发evn准备好的事件
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
configureIgnoreBeanInfo(environment);
Banner printedBanner = printBanner(environment);
context = createApplicationContext();
exceptionReporters = getSpringFactoriesInstances(
SpringBootExceptionReporter.class,
new Class[] { ConfigurableApplicationContext.class }, context);
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
refreshContext(context);
afterRefresh(context, applicationArguments);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
listeners.started(context);
callRunners(context, applicationArguments);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, listeners);
throw new IllegalStateException(ex);
}

try {
listeners.running(context);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, null);
throw new IllegalStateException(ex);
}
return context;
}

以上是“Spring Boot启动流程断点过程的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


当前文章:SpringBoot启动流程断点过程的示例分析
浏览路径:http://cdkjz.cn/article/peoodj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220