SpringBoot实战分析(一) 入门级启动过程
2018-06-11 16:31
501 查看
1.启动类
@SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }2.点击run,进入SpringApplication类中,调用
public static ConfigurableApplicationContext run(Class<?> primarySource, String... args) { return run(new Class<?>[] { primarySource }, args);//断点 }参数说明:primarySource:启动类的主类
args:为 { } 空值
3.SpringApplication调用
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) { return new SpringApplication(primarySources).run(args);//断点 }4.SpringApplication调用
public ConfigurableApplicationContext run(String... args) { //java 查看时间和性能的类 //https://blog.csdn.net/pandawang1989/article/details/78246316 StopWatch stopWatch = new StopWatch(); stopWatch.start(); //定义配置上下文 是个interface 顶级父类包含BeanFactory ConfigurableApplicationContext context = null; //定义一个错误集合 Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>(); //定义一个awt的headless configureHeadlessProperty(); //获取一个run监听器 SpringApplicationRunListeners listeners = getRunListeners(args); //启动监听 listeners.starting(); try { //应用程序参数 初始化 ApplicationArguments applicationArguments = new DefaultApplicationArguments( args); //创建和配置环境 入参:监听 应用程序参数 ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments); //配置bean的忽略信息 扫描 spring.beaninfo.ignore 可选true/fale //在application.yml中配置 configureIgnoreBeanInfo(environment); //打印logo信息 Banner printedBanner = printBanner(environment); //重点 重点 重点 说三遍 //创建app的上下文 初始化bean等操作都在这 后面再说 context = createApplicationContext(); exceptionReporters = getSpringFactoriesInstances( SpringBootExceptionReporter.class, new Class[] { ConfigurableApplicationContext.class }, context); //准备 使用上下文 prepareContext(context, environment, listeners, applicationArguments, printedBanner); //刷新上下文 这个也是 重点 重点 重点 //synchronized (this.startupShutdownMonitor) refreshContext(context); afterRefresh(context, applicationArguments); stopWatch.stop(); if (this.logStartupInfo) { new StartupInfoLogger(this.mainApplicationClass) .logStarted(getApplicationLog(), stopWatch); } //带上下文启动 listeners.started(context); //应该是唤醒运行的线程 callRunners(context, applicationArguments); } catch (Throwable ex) { handleRunFailure(context, ex, exceptionReporters, listeners); throw new IllegalStateException(ex); } try { //发布事件 listeners.running(context); } catch (Throwable ex) { handleRunFailure(context, ex, exceptionReporters, null); throw new IllegalStateException(ex); } return context; }所有写有注释的地方都断点跟踪的。
相关文章推荐
- SpringBoot——启动方式及过程分析
- Spring Boot 2.x 启动全过程源码分析(上)入口类剖析
- Spring Boot启动过程源码分析(二)事件监听器
- [Spring Boot] 1. Spring Boot启动过程源码分析
- Spring Boot实战与原理分析之快速入门
- Spring Boot启动过程源码分析
- SpringBoot应用启动过程分析
- SpringBoot启动过程分析
- Spring Boot实战与原理分析
- UBOOT启动过程及uboot.lds文件分析
- U-Boot 启动过程和源码分析(第二阶段)
- u-boot启动过程分析——基于lpc2210的移植代码
- Spring Boot - security 实战与源码分析
- u_boot启动过程中的具体分析(1)
- spring boot应用启动原理分析
- SpringBoot实战分析(六)创建应用程序上下文
- SpringBoot-Loader源码分析系列2:启动 new JarLauncher().launch(args)的.launch(args)部分
- spring boot实战(第十篇)Spring boot Bean加载源码分析
- u-boot_smdkv210 分析五:硬件启动过程
- Spring启动过程分析(一)