springboot 的启动流程
1.我们springboot 项目的启动类如下。
方式1
@SpringBootApplication
public class SpringbootZkLockApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootZkLockApplication.class, args);
}
}
点击 run 方法源码进入如下,
/**
* Static helper that can be used to run a {@link SpringApplication} from the
* specified source using default settings.
* @param primarySource the primary source to load
* @param args the application arguments (usually passed from a Java main method)
* @return the running {@link ApplicationContext}
*/
public static ConfigurableApplicationContext run(Class<?> primarySource, String... args) {
return run(new Class<?>[] { primarySource }, args);
}
继续 点击 run 方法进入源码,
/**
* Static helper that can be used to run a {@link SpringApplication} from the
* specified sources using default settings and user supplied arguments.
* @param primarySources the primary sources to load
* @param args the application arguments (usually passed from a Java main method)
* @return the running {@link ApplicationContext}
*/
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
return new SpringApplication(primarySources).run(args);
}
我们看到 run() 方法的返回值为 ConfigurableApplicationContext。
看到这里我们就知道了SpringBoot 启动类的底层 是 new SpringApplication(primarySources).run(args);
这时候我们的启动类可以可以换成 如下方式启动。
方式2
@SpringBootApplication
public class SpringbootZkLockApplication { public static void main(String[] args) {
//SpringApplication.run(SpringbootZkLockApplication.class, args);
new SpringApplication(SpringbootZkLockApplication.class).run(args);
}
new SpringApplication(SpringbootZkLockApplication.class).run(args); 可以拆分为2个部分启动
方式3
@SpringBootApplication
public class SpringbootZkLockApplication { public static void main(String[] args) {
//SpringApplication.run(SpringbootZkLockApplication.class, args);
SpringApplication application = new SpringApplication(SpringbootZkLockApplication.class);
application.run(args);
}
}
上面这三种启动方式都是等价的,都可以启动 SpringBoot 项目。只不过是第一种方式是我们常用的,经过SpringBoot 封装过的启动方式。
@EnableAutoConfiguration 注解 加载了我们第三方配置的信息进行 Tomcat 启动。
DispatcherServletAutoConfiguration ---》ServletWebServerFactoryAutoConfiguration 创建 tomcat。
springboot 的启动流程的更多相关文章
- SpringBoot IoC启动流程、初始化过程及Bean生命周期各个阶段的作用
目录 SpringBoot IoC启动流程.初始化过程及Bean生命周期各个阶段的作用 简述 首先明确IoC容器是啥 准备-SpringApplication的实例化 启动-SpringApplica ...
- SpringBoot的启动流程是怎样的?SpringBoot源码(七)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 温故而知新 本篇接 SpringBoot内置的各种Starter是怎样构建的? SpringBoot源码(六) 温故而知新, ...
- java框架之SpringBoot(10)-启动流程及自定义starter
启动流程 直接从 SpringBoot 程序入口的 run 方法看起: public static ConfigurableApplicationContext run(Object source, ...
- SpringBoot的启动流程分析(2)
我们来分析SpringApplication启动流程中的run()方法,代码如下 public ConfigurableApplicationContext run(String... args) { ...
- SpringBoot的启动流程分析(1)
通过分析我们可以找到 org.springframework.boot.SpringApplication 中如下, public static ConfigurableApplicationCont ...
- springboot 大致启动流程
SpringApplication的run方法的实现是我们本次旅程的主要线路,该方法的主要流程大体可以归纳如下: 1) 如果我们使用的是SpringApplication的静态run方法,那么,这个方 ...
- SpringBoot启动流程分析(六):IoC容器依赖注入
SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...
- SpringBoot启动流程分析(一):SpringApplication类初始化过程
SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...
- SpringBoot启动流程分析(二):SpringApplication的run方法
SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...
随机推荐
- Tosca 一不小心,我把那一排模块全关闭了,怎么打开
#写在前面, 之前用的时候,学了很多,基本都忘记了,现在再重新用,啥啥都不记得了,我还是应该事无巨细的全部记下来 红线这一排我关了好多,在哪儿打开 在这打开
- word: 插入或修改文字时后面的字消失 解决办法
在编辑Word文档中的文字时,我们有时需要插入或修改文字,可是在插入或修改时会发现改动处后面的文字会消失.比如插入或修改3个字,后面的文字随之也会消失3个,这时该怎么办呢? 点击-“文件”-“选项”- ...
- android -------- java.net.UnknownServiceException
最近升级了Android的API版本时 ,导致我的网络请求失败了, 出现了这个错误 java.net.UnknownServiceException, 这个错误,我在网上查到这个主要是由于,我们的Ok ...
- Java基础 Scanner 使用nextLine接收字符串
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- openresty开发系列22--lua的元表
openresty开发系列22--lua的元表 举个例子,在 Lua table 中我们可以访问对应的key来得到value值,但是却无法对两个 table 进行操作. 那如何计算两个table的相加 ...
- Xadmin权限管理
需求分析: 1.判断用户是否登陆,未登陆就不能进入其他页面2.为用户分配不同的权限,用户的操作只能在权限范围之内3.将用户可操作的权限显示在页面山,点击能进入该页面操作 模型表的建立 1.对每个用户建 ...
- 【转载】 linux dig 命令使用方法
原文地址: https://www.imooc.com/article/26971?block_id=tuijian_wz 作者:ibeautiful来源:慕课网 ------------------ ...
- ASP中如何将数据库内容导入到数组?并进行字符串对比
dim Arr sql1="select id from [aaa] where reader not like '%"&userid&"%'" ...
- C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式
C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式 置顶 2018年03月06日 19:16:51 黎筱曦 阅读数:19098 标签: C#时间 更多 个人 ...
- Python和Pygame游戏开发 pdf
Python和Pygame游戏开发 目录 第1章 安装Python和Pygame 11.1 预备知识 11.2 下载和安装Python 11.3 Windows下的安装说明 11.4 Mac OS X ...