1382行,真是又长又臭。捏着鼻子,干起来。

0~86行,版权、包名和import,略过。

87~161行,类注释信息,还是要看一下。

Class that can be used to bootstrap and launch a Spring application from a Java main method.
该类可以用在main方法中使用,用来启动一个Spring应用程序。
By default class will perform the following steps to bootstrap your application:
默认情况下,该类以下面的步骤启动程序:
Create an appropriate ApplicationContext instance (depending on your classpath)
根据类路径创建一个ApplicationContext实例
Register a CommandLinePropertySource to expose command line arguments as Spring properties
注册一个CommandLinePropertySource来将命令行参数作为Spring属性
Refresh the application context, loading all singleton beans
刷新程序上下文,加载所有的单例bean
Trigger any CommandLineRunner beans
触发全部CommandLineRunner beanIn most circumstances the static run(Class, String[]) method can be called directly from your main method to bootstrap your application:
在很多情况下,在main方法中直接调用静态方法run(Class, String[])来启动程序,代码如下:@Configuration@EnableAutoConfigurationpublic class MyApplication  {// ... Bean definitionspublic static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}}For more advanced configuration a SpringApplication instance can be created and customized before being run:
也可以调用实例方法run(String... args)来启动程序,这样需要先创建SpringApplication实例,但好处是这样做可以自定义参数配置,代码如下:public static void main(String[] args) {SpringApplication application = new SpringApplication(MyApplication.class);// ... customize application settings hereapplication.run(args)}SpringApplications can read beans from a variety of different sources.
SpringApplication可以从不同类型的sources中读取bean信息。
It is generally recommended that a single @Configuration class is used to bootstrap your application, however, you may also set sources from:
推荐这么做,main方法所在类用@Configuration修饰,但是并不影响我们设置sources的方法:
The fully qualified class name to be loaded by AnnotatedBeanDefinitionReader
由AnnotatedBeanDefinitionReader加载全完限定类名
The location of an XML resource to be loaded by XmlBeanDefinitionReader, or a groovy script to be loaded by GroovyBeanDefinitionReader
XmlBeanDefinitionReader加载XML resource,或者是GroovyBeanDefinitionReader加载groovy脚本
The name of a package to be scanned by ClassPathBeanDefinitionScanner
ClassPathBeanDefinitionScanner来根据报名扫描Configuration properties are also bound to the SpringApplication.
配置属性也绑定到SpringApplication
This makes it possible to set SpringApplication properties dynamically, like additional sources ("spring.main.sources" - a CSV list) the flag to indicate a web environment ("spring.main.web-application-type=none") or the flag to switch off the banner ("spring.main.banner-mode=off").
这么做使得能够动态设置SpringApplication的属性。(举了三个设置属性的例子,没翻译)Since:
1.0.0
See Also:
run(Class, String[]), run(Class[], String[]), SpringApplication(Class...)
Author:
Phillip Webb, Dave Syer, Andy Wilkinson, Christian Dupuis, Stephane Nicoll, Jeremy Rickard, Craig Burke, Michael Simons, Madhura Bhave, Brian Clozel, Ethan Rubinson
(都是一些与代码逻辑无关的信息。大概是
1.0.0版本就有这个类了
这段注解中提的的三个方法,这三个方法的使用去看这三个方法各自的注释,在IDE中是有提示窗的
作者就11个人,真是的!!难怪又臭又长..人家都是大佬啦,难怪自己看起来这么吃力
)

总结一下这段到底说了什么:

1. 这个用来启动Spring容器,然后这个类启动做了哪些事儿;

2. 用run方法启动,这个run方法有两个重载,一个静态方法一个实例方法,各自的优势;

3. 这个类支持从不同source读取bean的配置;

4. 通过此类能为Spring配置属性参数。(3和4就是说,通过这个类能方便的为Spring容器配置bean或者参数)。

162行,类名。这个类简直太好了,虽然长,但就是一个单独的类,没继承谁也没注解修饰。所以只是长,用线性思维分析就可以。相比,屏目前的你也松了口气吧。相信我们一定能看完。

public class SpringApplication {

163-204行,这里定义了6个String类型的常量,和一个日志对象。为了后面代码读起来比较通顺,对这些常量要有点印象。具体如下:

/*** The class name of application context that will be used by default for non-web* environments.默认情况下,非web环境的application context使用这里定义的类(用类名来指定的)。* @deprecated since 2.4.0 in favour of using a {@link ApplicationContextFactory}从2.4.0版本开始用ApplicationContextFactory代替。*/@Deprecatedpublic static final String DEFAULT_CONTEXT_CLASS = "org.springframework.context."+ "annotation.AnnotationConfigApplicationContext";/*** The class name of application context that will be used by default for web* environments.默认情况下,web环境使用这里指定的类作为application context。* @deprecated since 2.4.0 in favour of using an {@link ApplicationContextFactory}从2.4.0版本开始用ApplicationContextFactory代替。(反复提到类ApplicationContextFactory,暂且不想去看这个类,等用到再过去)*/@Deprecatedpublic static final String DEFAULT_SERVLET_WEB_CONTEXT_CLASS = "org.springframework.boot."+ "web.servlet.context.AnnotationConfigServletWebServerApplicationContext";/*** The class name of application context that will be used by default for reactive web(和上面的一样)默认对于响应式web环境使用这个常量指定的类作为application context。* environments.* @deprecated since 2.4.0 in favour of using an {@link ApplicationContextFactory}*/@Deprecatedpublic static final String DEFAULT_REACTIVE_WEB_CONTEXT_CLASS = "org.springframework."+ "boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext";/*** Default banner location.默认banner的位置。(就是Spring Boot程序已启动会在控制台打印Spring的标识,真的够无聊的,代码本来就够多了,还弄这些有的没的,徒给读源码的人增加阅读量,你们这11个作者是想考我们阅读理解吗?)*/public static final String BANNER_LOCATION_PROPERTY_VALUE = SpringApplicationBannerPrinter.DEFAULT_BANNER_LOCATION;/*** Banner location property key.banner位置的属性键,就是在配置文件中的key是什么,这里还指向了另一个常量。(我就说嘛,增加一个banner的打印,增加了不止一个类,何必呢。何必呢?(何必要在一起,让我没勇气,让我独自在这寒冷的夜里~何必要在一起~~~~~~~~~~~~))*/public static final String BANNER_LOCATION_PROPERTY = SpringApplicationBannerPrinter.BANNER_LOCATION_PROPERTY;private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";这行代码没给注解,但看常量名,应该是指定读取系统系统属性的key,网上搜了一下,是说Headless模式是系统的一种配置模式。在该模式下,系统缺少了显示设备、键盘或鼠标。在430行configureHeadlessProperty这个方法中用到了。没太懂,先跳过吧。有点印象,等用到这个方法再细看。private static final Log logger = LogFactory.getLog(SpringApplication.class);这个就是个日志输出的对象了,太熟悉了~~

2021.4.6,先这样吧,明天继续。

手撕源码之SpringApplication.java【Spring Boot 2.4.4】相关推荐

  1. 【源码阅读】看Spring Boot如何自动装配ActiveMQ收发组件

    源于好奇,我研究了一下Spring Boot中ActiveMQ相关组件是如何自动装配的.记录如下. 源码路径 本文以Spring Boot 1.5.10.RELEASE版本为例. 在spring-bo ...

  2. spring手撕源码

    1 spring 的bean的生命周期 1.spring的核心容器ApplicationContext来实现spring启动时将所有的bean扫描并注册到容器里,这个过程中会根据我们定义的bean之间 ...

  3. (附源码)小程序+spring boot校园二手交易平台 毕业设计 191637

    Springboot校园二手交易平台小程序 摘 要 信息化社会内需要与之针对性的信息获取途径,但是途径的扩展基本上为人们所努力的方向,由于站在的角度存在偏差,人们经常能够获得不同类型信息,这也是技术最 ...

  4. 高精度人员定位系统源码,采用vue+spring boot框架,支持二次开发

    智慧工厂人员定位系统源码,高精度人员定位系统源码,UWB定位技术 文末获取联系! 在工厂日常生产活动中,企业很难精准地掌握访客和承包商等各类人员的实际位置,且无法实时监控巡检人员的巡检路线,当厂区发生 ...

  5. 源码 | Arduino + EMQ X + Spring Boot + Vue 开源全栈物联网智能家居系统

    物美智能(wumei-smart)是一套开源的软硬件系统,可用于二次开发和学习,快速搭建自己的智能家居系统.硬件工程师可以把自己的设备集成到系统:软件工程师可以使用项目中的设备熟悉软硬件交互. 01 ...

  6. [评论送书 ]手撕源码,实现一个Koa。

    大家好,我是半夏

  7. javaweb高速公路模拟ETC收费系统的设计与实现.rar(项目源码+毕业设计+数据库文件) spring boot+mysql

    1 绪论 5 1.1 系统开发背景 5 1.2 系统开发意义 5 1.3项目主要的内容 5 2 系统开发工具介绍 6 2.1 JSP技术概述 6 2.2 JAVA语言 7 2.3 IDEA开发工具简介 ...

  8. 【源码分享】java多用户B2B2C商城源码带WAP手机端源码

    分享一款非常不错的java多用户B2B2C商城源码,带WAP手机端源码,源码地址在文末. 需要源码学习,可私信我获取. 一.技术构架: 开发语言: Java1.7 数 据 库 : MySQL5.5 数 ...

  9. 面试有没有看过spring源码_如何看Spring源码、Java每日六道面试分享,打卡第二天...

    原标题:如何看Spring源码.Java每日六道面试分享,打卡第二天 想要深入的熟悉了解Spring源码,我觉得第一步就是要有一个能跑起来的极尽简单的框架,下面我就教大家搭建一个最简单的Spring框 ...

  10. java报错找不到对象,使用Spring源码报错java:找不到类 InstrumentationSavingAgent的问题...

    使用Spring源码,报错java:找不到类 InstrumentationSavingAgent 报错如下: Error:(26, 38) java: 找不到符号 符号: 类 Instrumenta ...

最新文章

  1. Pandas简明教程:八、Pandas数据透视表
  2. POJ - 1220 NUMBER BASE CONVERSION(高精度运算+进制转换+模拟)
  3. linux安装mysql 5.6.33
  4. php聊天室技术,PHP聊天室技术
  5. Jmeter(四十八)_动态线程分析HTML测试报告
  6. CSRF verification failed. Request aborted.的解决办法
  7. 【算法导论】0-1背包问题 与 部分背包
  8. java图形化元件竖直排列_Java:图形化比较排序
  9. NHibernate ModelBinder for mvc3
  10. [Jscript]Js导出Excel
  11. ubuntu 18.04 pycharm生成快捷方式 ,亲测有效!!
  12. 真实的感情---可是你没有
  13. 分析全基因组上的蛋白信息
  14. 编写一个静态方法lg(),接收一个整型参数N,返回不大于log2N(以2为底)的最大整数。不要使用Math库。
  15. 课堂笔记(常用软件,网站资源)
  16. 好记性不如烂笔头-笔记记录方法公开
  17. win10c语言关机,win10如何设置定时关机?
  18. 尚医通-OAuth2-微信登录接口开发(三十一)
  19. 一分钱不花,教你白piao一套自己的云笔记系统
  20. gorm实现insert ignore into语句调用

热门文章

  1. nod32 update and id
  2. 2k2实用球员_2KOL2王朝不知道用谁?五大位置低价实用球员大解析!
  3. Hibernate 主键
  4. php smarty数学函数,smarty详解二:从文件读取变量、保留变量、数学计算、内建函数...
  5. linux查看耗费流量的进程--iftop
  6. python画图小实例_Python画高斯分布图形实例代码
  7. micropython ide 8266_老外开发的MicroPython IDE,可用于开发ESP8266
  8. matlab中esp=1.0e-3,ESP系列杂谈(一): eFuse 简介
  9. html与css怎么混合运用,Web设计中的CSS混合模式
  10. 102 二叉树层序遍历Binary Tree Level Order Traversal @ Python