当前位置: 首页 > news >正文

SpringBoot:SpringBoot启动加载过程 ④

一、思想

      我们看到技术上高效简单的使用,其实背后除了奇思妙想的开创性设计,另一点是别人帮你做了复杂繁琐的事情。

二、从官网Demo入手

        官网就一行代码。这个就是它的启动代码。

 

        1、@SpringBootApplication注解

                ①.  三个核心注解的整合。

                        @SpringBootConfiguration  (配置注入)

                        @ComponentScan(包下bean组件扫描)

                        @EnableAutoConfiguration     (开启自动配置)

                        (每一个注解都是一个故事,目前咱们只是窥探轮廓)

                

         2、Run代码

                        ① 加载配置文件

                        ②  装载Bean容器,以及监听器启动在其中监控对象的创建过程。

                        ③  加载所有的注解的bean以及自动配置的spring.factories 设置的所有bean

                        ④ 把应用放入内嵌的tomcat服务中

    public ConfigurableApplicationContext run(String... args) {StopWatch stopWatch = new StopWatch();stopWatch.start();ConfigurableApplicationContext context = null;Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList();this.configureHeadlessProperty();SpringApplicationRunListeners listeners = this.getRunListeners(args);listeners.starting();Collection exceptionReporters;try {ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);this.configureIgnoreBeanInfo(environment);Banner printedBanner = this.printBanner(environment);context = this.createApplicationContext();exceptionReporters = this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);this.prepareContext(context, environment, listeners, applicationArguments, printedBanner);this.refreshContext(context);this.afterRefresh(context, applicationArguments);stopWatch.stop();if (this.logStartupInfo) {(new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);}listeners.started(context);this.callRunners(context, applicationArguments);} catch (Throwable var10) {this.handleRunFailure(context, var10, exceptionReporters, listeners);throw new IllegalStateException(var10);}try {listeners.running(context);return context;} catch (Throwable var9) {this.handleRunFailure(context, var9, exceptionReporters, (SpringApplicationRunListeners)null);throw new IllegalStateException(var9);}}

                        

 

 

http://www.lryc.cn/news/93191.html

相关文章:

  • 抽象轻松JavaScript
  • 深入理解CSS字符转义行为
  • 【论文阅读】(2023.05.10-2023.06.03)论文阅读简单记录和汇总
  • FPGA开发-ddr测试
  • BUUCTF 大帝的密码武器 1
  • Linux 查看目录个数和大小
  • Unity制作二次元卡通渲染角色材质——4 、内外描边和细节添加
  • Ubuntu安装GCC10
  • 【flutter】Dart 规范2
  • k8s CoreDns详解
  • c++ 连sqlserver
  • 给钉钉的2个建议
  • STL之优先级队列(堆)的模拟实现与仿函数(8千字长文详解!)
  • 设施管理系统
  • JavaScript:获取当前日期、星期、时间 | Data对象
  • Cadence原理图快速查找元器件的方法
  • 科目二 调整座椅
  • 02.加载GDT表,进入保护模式
  • MySQL(进阶篇3.0)
  • 2023.6.8小记——嵌入式系统初识、什么是ARM架构?
  • 分布式运用之ELK企业级日志分析系统
  • 【华为OD机试真题 C语言】8、停车场车辆统计 | 机试真题+思路参考+代码解析
  • c++ MES 对接(XML、JSON、SOAP)
  • idea导入java web项目带jar
  • 【第55天|● 392.判断子序列 ● 115.不同的子序列 】
  • Dockerfile创建镜像
  • 基于 opencv 的人脸识别上课考勤系统,附源码,可作为毕业设计
  • .editorconfig 配置
  • Spring 高级依赖注入 —— Bean的延迟依赖查找功能,ObjectFactory 和 ObjectProvider
  • VSCode--Config