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。

最新文章

  1. Spring基础知识
  2. DIV+CSS布局网站基本框架
  3. Java语言的编写规范
  4. UITextField属性
  5. Css:背景色透明,内容不透明之终极方法!兼容所有浏览器
  6. HTML to DOM
  7. MapReduce中使用SequenceFile的方式上传文件到集群中
  8. 如何嗅闻交换网络和ARP骗子-ARP解释的原则
  9. NSIndexSet 浅析
  10. c# ProxyServer 代理服务器 不是很稳定
  11. 【python】函数说明文档
  12. 0 - Dao层(数据访问层设计)
  13. git步骤
  14. MySql 5.7.20版本免安装版配置过程
  15. txt2xls
  16. ComponetOne 2014 v3版本正式发布
  17. 深入详解美团点评CAT跨语言服务监控(八)报表持久化
  18. GoLang学习之数据类型
  19. linux内核分析第一次实验
  20. 【js】用正则表达式对文字进行局部替换

热门文章

  1. JS数组常见方法的深浅拷贝分类
  2. Xcode: Xcode中Command Line Tools的安装方法
  3. MySQL not equal to operator &lt;&gt; &amp;&amp; !=
  4. autoComplete TextView
  5. 关于TCP粘包和拆包的终极解答
  6. 003-结构型-02-装饰模式(Decorator)
  7. DELPHI 数据库操作类(工具类)
  8. IBM System x3650 M3_RAID服务器进入阵列卡配置界面(webBIOS)
  9. [转]Ubuntu 上创建常用磁盘阵列
  10. Difference between Process and thread?