首页 > 编程语言 > 详细

HM-SpringBoot2.8【SpringBoot启动流程分析】

时间:2021-08-02 23:28:19      阅读:49      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

 


 

 

技术分享图片

 

 


 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

SpringApplication是事件源对象,所有对象都是通过这个对象产生的

1 SpringApplication的构造方法

技术分享图片

 

 

 1 public SpringApplication(Class... primarySources) {
 2         this((ResourceLoader)null, primarySources);
 3     }
 4 
 5     public SpringApplication(ResourceLoader resourceLoader, Class... primarySources) {
 6         this.sources = new LinkedHashSet();
 7         this.bannerMode = Mode.CONSOLE;
 8         this.logStartupInfo = true;
 9         this.addCommandLineProperties = true;
10         this.addConversionService = true;
11         this.headless = true;
12         this.registerShutdownHook = true;
13         this.additionalProfiles = Collections.emptySet();
14         this.isCustomEnvironment = false;
15         this.lazyInitialization = false;
16         this.applicationContextFactory = ApplicationContextFactory.DEFAULT;
17         this.applicationStartup = ApplicationStartup.DEFAULT;
18         this.resourceLoader = resourceLoader;
19         Assert.notNull(primarySources, "PrimarySources must not be null");
20         this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
21         this.webApplicationType = WebApplicationType.deduceFromClasspath();
22         this.bootstrapRegistryInitializers = this.getBootstrapRegistryInitializersFromSpringFactories();
23         this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
24         this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
25         this.mainApplicationClass = this.deduceMainApplicationClass();
26     }

 

技术分享图片

 

 技术分享图片

 

 

2 SpringApplication的run()

 

 1 public ConfigurableApplicationContext run(String... args) {
 2         StopWatch stopWatch = new StopWatch();
 3         stopWatch.start();
 4         DefaultBootstrapContext bootstrapContext = this.createBootstrapContext();
 5         ConfigurableApplicationContext context = null;
 6         this.configureHeadlessProperty();
 7         SpringApplicationRunListeners listeners = this.getRunListeners(args);
 8         listeners.starting(bootstrapContext, this.mainApplicationClass);
 9 
10         try {
11             ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
12             ConfigurableEnvironment environment = this.prepareEnvironment(listeners, bootstrapContext, applicationArguments);
13             this.configureIgnoreBeanInfo(environment);
14             Banner printedBanner = this.printBanner(environment);
15             context = this.createApplicationContext();
16             context.setApplicationStartup(this.applicationStartup);
17             this.prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
18             this.refreshContext(context);
19             this.afterRefresh(context, applicationArguments);
20             stopWatch.stop();
21             if (this.logStartupInfo) {
22                 (new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);
23             }
24 
25             listeners.started(context);
26             this.callRunners(context, applicationArguments);
27         } catch (Throwable var10) {
28             this.handleRunFailure(context, var10, listeners);
29             throw new IllegalStateException(var10);
30         }
31 
32         try {
33             listeners.running(context);
34             return context;
35         } catch (Throwable var9) {
36             this.handleRunFailure(context, var9, (SpringApplicationRunListeners)null);
37             throw new IllegalStateException(var9);
38         }
39     }

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

技术分享图片

 

 技术分享图片

 

 

 

技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 课上老师演示效果:

 

技术分享图片

 本地实际操作效果(不知道springboot更新了其他设置,还是自己操作出错了):

 技术分享图片

 

 


 

HM-SpringBoot2.8【SpringBoot启动流程分析】

原文:https://www.cnblogs.com/yppah/p/15091971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!