* 这里通过Spring Boot自动配置了Tomcat,如果想要深入可以追着#getWebServerFactory看 * 下面有对应的不太详细的解释 */privatevoidcreateWebServer(){WebServerwebServer=this.webServer;ServletContextservletContext=getServletContext();if(webServer ==null&& servletContext ==null) {ServletWebServerFactoryfactory=g...
可以看到里面也通过@Import注解将EmbeddedTomcat、EmbeddedJetty、EmbeddedUndertow等嵌入式容器类加载进来了,springboot默认是启动嵌入式tomcat容器,如果要改变启动jetty或者undertow容器,需在pom文件中去设置。 这里默认实现的是Tomcat容器,那么看一下EmbeddedTomcat: 进入TomcatServletWebServerFactory类,里面的getWebServer()是...
//Tomcat 工厂创建publicclassTomcatServletWebServerFactoryextendsAbstractServletWebServerFactoryimplementsConfigurableTomcatWebServerFactory, ResourceLoaderAware {//现在默认的协议privateString protocol = "org.apache.coyote.http11.Http11NioProtocol";publicWebServer getWebServer(ServletContextInitializer... initializers...
其中getWebServerFactory获取到的是TomcatServletWebServerFactory,相应的 factory.getWebServer(getSelfInitializer())获取到的 就是TomcatServer 在factory.getWebServer(getSelfInitializer())过程中,其实已经讲tomcat启动起来了 为什么默认是tomcat,主要是因为springboot默认引入了spring-boot-starter-tomcat包,使TomcatServle...
一、ServletWebServerFactoryConfiguration 实际上,spring boot是指出多种服务器启动的,并不只是tomcat,还有jetty等。因此我们可以猜测具体哪种服务器是可以配置的,而spring boot又是以自动配置闻名,那么这些服务器肯定与某些自动配置类相关。 实际上,spring boot的servlet web服务器的配置类就是位于spring-boot-autoconfigur...
SpringBoot是如何启动内置tomcat的SpringApplication.run(HppaApplication.class, args);这个会最终调用到一个同名方法run(String... args)public ConfigurableApplicationContext run(String... args) { //StopWatch主要是用来统计每项任务执行时长,例如Spring Boot启动占用总时长。 StopWatch stopWatch = new StopWatch...
Springboot内嵌的各种web容器实例,都是在onRefresh()中进行创建的。查看方法实现可以发现这个方法是个空方法 protected void onRefresh() throws BeansException {// For subclasses: do nothing by default.} 但是其子类的都实现了这个方法,子类列表如下 因为Tomcat是一个Servlet容器,所以我们直接看ServletWebServer...
容器Maven依赖webServer实现类 Tomcatspring-boot-starter-tomcatTomcatWebServer Jettyspring-boot-starter-...
现在让我们从springboot启动开始一步步分析TomCat是如何启动的,并如何将springBoot中的URL业务处理方法注册入TomCat中的。 SpringApplication.run()方法是项目启动的地址,在创建context的时候会根据服务的类型创建对应的context 我们是servlet项目,所有创建AnnotationConfigServletWebServerApplicationContext实现对象, ...