When does springBoot load Tomcat, Spring,spring MVC

public static void main(String[] args) { SpringApplication.run(SpringbootStartApplication.class, args); } public SpringApplication(ResourceLoader ResourceLoader, Class... primarySources) { this.sources = new LinkedHashSet(); this.bannerMode = Mode.CONSOLE; this.logStartupInfo = true; this.addCommandLineProperties = true; this.headless = true; this.registerShutdownHook = true; this.additionalProfiles = new HashSet(); this.resourceLoader = resourceLoader; Assert.notNull(primarySources, "PrimarySources must not be null"); this.primarySources = new LinkedHashSet(Arrays.asList(primarySources)); / / 1. Should be Standard or Web application type (judged by whether there is a class) enclosing webApplicationType = this. DeduceWebApplicationType (); this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class)); this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class)); this.mainApplicationClass = this.deduceMainApplicationClass(); } public ConfigurableApplicationContext run(String... args) { ConfigurableApplicationContext context = null; Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList(); this.configureHeadlessProperty(); / / 1 - get SpringApplicationRunListeners SpringApplicationRunListeners listeners = this. GetRunListeners (args); // Listeners.starting(); Collection exceptionReporters; ApplicationArguments applicationArguments = new DefaultApplicationArguments(args); / / 2 - based on SpringApplicationRunListeners and parameters to prepare environment ConfigurableEnvironment environment = this. PrepareEnvironment (listeners,  applicationArguments); this.configureIgnoreBeanInfo(environment); / / 3 - create a Spring context context = this. CreateApplicationContext (); PrepareContext (Context, environment, listeners, applicationArguments, printedBanner); // refresh this. RefreshContext (context); AfterRefresh (context, applicationArguments); // Notice of events ending execution. Context; this.callRunners(context, applicationArguments); listeners.running(context); return context; }Copy the code

//SpringApplication private void refreshContext(ConfigurableApplicationContext context) { this.refresh(context); //AnnotationConfigServletWebServerApplicationContext if(this.registerShutdownHook) { try { context.registerShutdownHook(); } catch (AccessControlException var3) { ; } } } //ServletWebServerApplicationContext public final void refresh() throws BeansException, IllegalStateException { try { super.refresh(); } catch (RuntimeException var2) { this.stopAndReleaseWebServer(); throw var2; } } //AbstractApplicationContext public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { prepareRefresh(); ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); prepareBeanFactory(beanFactory); postProcessBeanFactory(beanFactory); invokeBeanFactoryPostProcessors(beanFactory); registerBeanPostProcessors(beanFactory); initMessageSource(); initApplicationEventMulticaster(); onRefresh(); // Tomcat start registerListeners(); finishBeanFactoryInitialization(beanFactory); finishRefresh(); } //ServletWebServerApplicationContext private void createWebServer() { WebServer webServer = this.webServer; ServletContext servletContext = this.getServletContext(); if(webServer == null && servletContext == null) { ServletWebServerFactory factory = this.getWebServerFactory(); this.webServer = factory.getWebServer(new ServletContextInitializer[]{this.getSelfInitializer()}); } else if(servletContext ! = null) { try { this.getSelfInitializer().onStartup(servletContext); } catch (ServletException var4) { throw new ApplicationContextException("Cannot initialize servlet context", var4); } } this.initPropertySources(); } //TomcatServletWebServerFactory public WebServer getWebServer(ServletContextInitializer... initializers) { Tomcat tomcat = new Tomcat(); File baseDir = this.baseDirectory ! = null? this.baseDirectory:this.createTempDir("tomcat"); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); tomcat.getService().addConnector(connector); this.customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); this.configureEngine(tomcat.getEngine()); Iterator var5 = this.additionalTomcatConnectors.iterator(); while(var5.hasNext()) { Connector additionalConnector = (Connector)var5.next(); tomcat.getService().addConnector(additionalConnector); } this.prepareContext(tomcat.getHost(), initializers); return this.getTomcatWebServer(tomcat); } //TomcatWebServer private void initialize() throws WebServerException { logger.info("Tomcat initialized with port(s): " + this.getPortsDescription(false)); Object var1 = this.monitor; synchronized(this.monitor) { try { this.addInstanceIdToEngineName(); Context context = this.findContext(); context.addLifecycleListener((event) -> { if(context.equals(event.getSource()) && "start".equals(event.getType())) { this.removeServiceConnectors(); }}); this.tomcat.start(); this.rethrowDeferredStartupExceptions(); try { ContextBindings.bindClassLoader(context, context.getNamingToken(), this.getClass().getClassLoader()); } catch (NamingException var5) { ; } this.startDaemonAwaitThread(); } catch (Exception var6) { this.stopSilently(); throw new WebServerException("Unable to start embedded Tomcat", var6); }}}Copy the code