Spring Boot 自定义嵌入式 Servlet 容器

本文介绍 Spring Boot 2 自定义嵌入式 Servlet 容器的方法。


目录

  • Servlet 容器简介
  • Tomcat 容器依赖配置
  • Jetty 容器依赖配置
  • Undertow 容易依赖配置
  • 总结

Servlet 容器简介

Spring Boot 支持的嵌入式 Servlet 容器包括:

  • Tomcat
  • Jetty
  • Undertow

Tomcat 容器依赖配置


    
        org.springframework.boot
        spring-boot-starter-web
    

启动日志:

......
2019-04-30 15:08:59.120  INFO 15040 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-04-30 15:08:59.157  INFO 15040 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-04-30 15:08:59.158  INFO 15040 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-30 15:08:59.322  INFO 15040 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-04-30 15:08:59.322  INFO 15040 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1874 ms
2019-04-30 15:08:59.616  INFO 15040 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-30 15:08:59.891  INFO 15040 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
......

Jetty 容器依赖配置


    
        org.springframework.boot
        spring-boot-starter-web
        
            
            
                org.springframework.boot
                spring-boot-starter-tomcat
            
        
    
    
    
        org.springframework.boot
        spring-boot-starter-jetty
    

启动日志:

......
2019-04-30 15:06:28.345  INFO 9192 --- [           main] org.eclipse.jetty.util.log               : Logging initialized @2897ms to org.eclipse.jetty.util.log.Slf4jLog
2019-04-30 15:06:28.461  INFO 9192 --- [           main] o.s.b.w.e.j.JettyServletWebServerFactory : Server initialized with port: 8080
2019-04-30 15:06:28.464  INFO 9192 --- [           main] org.eclipse.jetty.server.Server          : jetty-9.4.15.v20190215; built: 2019-02-15T16:53:49.381Z; git: eb70b240169fcf1abbd86af36482d1c49826fa0b; jvm 1.8.0_201-b09
2019-04-30 15:06:28.510  INFO 9192 --- [           main] o.e.j.s.h.ContextHandler.application     : Initializing Spring embedded WebApplicationContext
2019-04-30 15:06:28.510  INFO 9192 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1612 ms
2019-04-30 15:06:28.675  INFO 9192 --- [           main] org.eclipse.jetty.server.session         : DefaultSessionIdManager workerName=node0
2019-04-30 15:06:28.675  INFO 9192 --- [           main] org.eclipse.jetty.server.session         : No SessionScavenger set, using defaults
2019-04-30 15:06:28.677  INFO 9192 --- [           main] org.eclipse.jetty.server.session         : node0 Scavenging every 660000ms
2019-04-30 15:06:28.690  INFO 9192 --- [           main] o.e.jetty.server.handler.ContextHandler  : Started o.s.b.w.e.j.JettyEmbeddedWebAppContext@6f80fafe{application,/,[file:///C:/Users/jwx620862/AppData/Local/Temp/jetty-docbase.1058292241481380235.8080/],AVAILABLE}
2019-04-30 15:06:28.691  INFO 9192 --- [           main] org.eclipse.jetty.server.Server          : Started @3240ms
2019-04-30 15:06:28.945  INFO 9192 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-30 15:06:29.198  INFO 9192 --- [           main] o.e.j.s.h.ContextHandler.application     : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-30 15:06:29.198  INFO 9192 --- [           main] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-04-30 15:06:29.205  INFO 9192 --- [           main] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms
2019-04-30 15:06:29.246  INFO 9192 --- [           main] o.e.jetty.server.AbstractConnector       : Started ServerConnector@26f3d90c{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-04-30 15:06:29.252  INFO 9192 --- [           main] o.s.b.web.embedded.jetty.JettyWebServer  : Jetty started on port(s) 8080 (http/1.1) with context path '/'
......

Undertow 容器依赖配置


        
            org.springframework.boot
            spring-boot-starter-web
            
                
                
                    org.springframework.boot
                    spring-boot-starter-tomcat
                
            
        
        
        
            org.springframework.boot
            spring-boot-starter-undertow
        
    

启动日志:

......
2019-04-30 15:11:49.253  WARN 3376 --- [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-04-30 15:11:49.297  INFO 3376 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2019-04-30 15:11:49.297  INFO 3376 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1631 ms
2019-04-30 15:11:49.675  INFO 3376 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-30 15:11:49.949  INFO 3376 --- [           main] org.xnio                                 : XNIO version 3.3.8.Final
2019-04-30 15:11:49.967  INFO 3376 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.3.8.Final
2019-04-30 15:11:50.079  INFO 3376 --- [           main] o.s.b.w.e.u.UndertowServletWebServer     : Undertow started on port(s) 8080 (http) with context path ''
......

你可能感兴趣的:(Spring Boot 自定义嵌入式 Servlet 容器)