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 }
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