首页 > 其他分享 >SpringBoot启动过程(二)

SpringBoot启动过程(二)

时间:2022-10-26 17:33:48浏览次数:91  
标签:Ordered SpringBoot PRECEDENCE 启动 DEFAULT ORDER 设置 过程 order

​​上一篇 ​​https://blog.51cto.com/u_15815563/5787667​

说到设置了初始化器。


设置listener

现在,同样的一套流程,这次要实例化的是实现了ApplicationListener的类,并存入listeners变量。


按照order排序,下面列出各个监听器的优先级顺序

第一,RestartApplicationListener, order=HIGHEST_PRECEDENCE=-2147483648,最高优先级。

第二,BootstrapApplicationListener,order=Ordered.HIGHEST_PRECEDENCE + 5 = -2147483643

第三,LoggingSystemShutdownListener,BootstrapApplicationListener.DEFAULT_ORDER + 1; 第二的顺序+1

第四,ConfigFileApplicationListener, Ordered.HIGHEST_PRECEDENCE + 10;

第五,AnsiOutputApplicationListener,ConfigFileApplicationListener.DEFAULT_ORDER + 1

第六,LoggingApplicationListener,Ordered.HIGHEST_PRECEDENCE + 20

第七,ClasspathLoggingApplicationListener,LoggingApplicationListener.DEFAULT_ORDER + 1

第八,BackgroundPreinitializer,LoggingApplicationListener.DEFAULT_ORDER + 1 (和第七是一样的大小)

第九,RestartListener, order=0

第十,DelegatingApplicationListener, order=0

第十一,ParentContextCloserApplicationListener, order=Ordered.LOWEST_PRECEDENCE - 10

第十二,DevToolsLogFactory.Listener ,无order设置,默认最低

第十三,ClearCachesApplicationListener,无order设置,默认最低

第十四,FileEncodingApplicationListener,显式最低,Ordered.LOWEST_PRECEDENCE

第十五,LiquibaseServiceLocatorApplicationListener,无order设置,默认最低


最后四个,都是最低优先级,有的没有设置,有的设置了是最低。

前八个多是SpringBoot系统级别的第一级别优先级梯队,都是很小的复数。


设置mainApplicationClass

在实例化的最后一步,是判断,运行main方法的主类。

方法如下

  private Class<?> deduceMainApplicationClass() {
try {
StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if ("main".equals(stackTraceElement.getMethodName())) {
return Class.forName(stackTraceElement.getClassName());
}
}
}
catch (ClassNotFoundException ex) {
// Swallow and continue
}
return null;
}

通过遍历堆栈,如果方法名是 main,就判定为启动的类。


至此,SpringApplication实例化结束。


下一步是执行run方法,在下一篇进行。


标签:Ordered,SpringBoot,PRECEDENCE,启动,DEFAULT,ORDER,设置,过程,order
From: https://blog.51cto.com/u_15815563/5798116

相关文章

  • Springboot 一行代码实现文件上传 20个平台!少写代码到极致
    又是做好人好事的一天,有个小可爱私下问我有没有好用的springboot文件上传工具,这不巧了嘛,正好我私藏了一个好东西,顺便给小伙伴们也分享一下,demo地址放在文末了。文件上传......
  • SpringBoot配置RabbitMQ
    一、导入Maven依赖<!--Springboot父依赖--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-......
  • SpringBoot
    依赖管理SpringBoot项目里面有一个<parent><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</art......
  • Docker部署Springboot WebAPI项目
    确定docker安装好Client:Version:20.10.12APIversion:1.41Goversion:go1.17.3Gitcommit:20.10.12-0ubuntu4Built:......
  • springboot mybatis-plus dao层调用异常 Invalid bound statement (not found)
    记录一次打包事故。  和同事共同开发项目。开发时访问都是ok。打包后再访问一直报org.apache.ibatis.binding.BindingException:Invalidboundstatement(notfound......
  • springboot使用mybatis连接oracle简单使用
    建表createtablepublic_memo(idsvarchar2(32)notnull,titlevarchar2(255)notnull,contentsclobnotnull,addressvarchar(255)notnull,......
  • ventoy启动盘工具
    Ventoy简介简单来说,Ventoy是一个制作可启动U盘的开源工具。有了Ventoy你就无需反复地格式化U盘,你只需要把ISO/WIM/IMG/VHD(x)/EFI等类型的文件直接拷贝到U盘里面就可......
  • jsp项目运行过程中出现的问题:
    报错问题描述:/admin/insert.jsp(行.:[33],列:[7])根据标记文件中的TLD或attribute指令,attribute[items]不接受任何表达式   web.xml中版本号不兼容产生的问......
  • 传统 API 管理与测试过程正面临严峻的挑战
    随着测试左移思想的引入,API(应用程序编程接口)经济的飞速增长,导致对API管理平台的需求相应增加。越来越多的企业注重并关注接口测试。单纯的做接口测试或者做好接口测试的......
  • springboot2 jackson 实现动态返回类字段
    问题与需求自从前后端分离的开发模式广泛普及之后,JSON便成为了端到端交互的首选数据结构。我们在使用java开发后端接口的时候,往往会出现我们一个类有十来个字段,但是前......