Spring boot中使用的是内置的Tomcat,而不像Spring mvc那样依赖外部tomcat运行项目。
spring boot中导入了Tomcat的jar包:
点进一个Spring boot 项目的application类的run方法:
查看此方法的实现类:
查看其实现类:
就是下面这段代码:
@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); }
其getTomcatWebServer方法:
上面启动tomcat并设置守护线程。