spring boot 在什么时候启动的tomcat
2018-03-04 12:02
537 查看
我一直很好奇 spring boot 以哪种方式 启动的 tomcat 今天 特地跟踪了一下
大家都知道 spring 容器很核心的 方式 是org.springframework.context.support.AbstractApplicationContext#refresh 这个方法
其中
调用的是 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#onRefresh
ps:在 springApplication.run 方法中 已jar包运行 启动的为org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext 这个上线文容器
然后 是 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer
大家都知道 spring 容器很核心的 方式 是org.springframework.context.support.AbstractApplicationContext#refresh 这个方法
其中
try { // Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory); // Initialize message source for this context. initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. onRefresh(); // Check for listener beans and register them. registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); }
调用的是 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#onRefresh
ps:在 springApplication.run 方法中 已jar包运行 启动的为org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext 这个上线文容器
@Override protected void onRefresh() { super.onRefresh(); try { createWebServer(); } catch (Throwable ex) { throw new ApplicationContextException("Unable to start web server", ex); } }
然后 是 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer
@Override public WebServer getWebServer(ServletContextInitializer... initializers) { Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null ? this.baseDirectory : createTempDir("tomcat")); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); tomcat.getService().addConnector(connector); customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); configureEngine(tomcat.getEngine()); for (Connector additionalConnector : this.additionalTomcatConnectors) { tomcat.getService().addConnector(additionalConnector); } prepareContext(tomcat.getHost(), initializers); return getTomcatWebServer(tomcat); }
相关文章推荐
- Spring Boot+Shiro+Redis(redisson)整合时,采用内嵌tomcat启动错误原因分析
- SpringBoot问题(Tomcat启动失败)
- Spring boot项目Tomcat启动与切换
- Spring-boot非Mock测试MVC,调试启动tomcat容器
- Spring Boot启动过程(五)之Springboot内嵌Tomcat对象的start教程详解
- SpringBoot从Eclipse添加的Tomcat容器中启动
- Spring Boot+Shiro+Redis(redisson)整合时,采用内嵌tomcat启动错误原因分析
- Unregistering JMX-exposed beans on shutdown :spring boot的tomcat插件启动失败
- spring boot项目启动,Tomcat报端口已被使用
- Spring boot 嵌入的tomcat不启动
- spring-boot项目启动失败的一种解决办法:自带的tomcat容器切换成jetty容器
- Spring Boot+Shiro+Redis(redisson)整合时,采用内嵌tomcat启动错误原因分析
- Spring Boot (一) 基础搭建、兼容jar启动及war tomcat启动、集成Swagger2 API。
- SpringBoot Tomcat启动实例代码详解
- springboot 整合jsp版本war包Tomcat启动不起来
- Spring Boot+Shiro+Redis(redisson)整合时,采用内嵌tomcat启动错误原因分析
- springboot 内置默认启动tomcat容器遇到The valid characters are defined in RFC 7230 and RFC 3986”
- Spring Boot启动过程(六):内嵌Tomcat中StandardHost、StandardContext和StandardWrapper的启动
- SpringgBoot入门系列篇(十三):部署SpringBoot到tomcat上并启动
- springBoot tomcat启动