0
点赞
收藏
分享

微信扫一扫

27. SpringBoot 切换内嵌Servlet容器

我们之前自己写过一个Servlet容器 ,EmbeddedServletContainerCustomizer ,直接加入到SpringBoot容器即可,他默认是Tomcat ,我们可以选中他 按 Ctrl + h  查看树,然后就可以发现 :

SpringBoot 默认支持3个Servlet容器,默认使用是 Tomcat :

27. SpringBoot 切换内嵌Servlet容器_spring

 

 

 1Tomcat 2Undertow 3 Jetty

 

现在我们尝试把Tomcat刚换成 Undertow 和  Jetty 

Undertow  不支持JSPJetty 适用于长连接

 

为什么默认用Tomcat 因为依赖了Tomcat 我们吧依赖exinclude27. SpringBoot 切换内嵌Servlet容器_servlet容器_02

 

然后我们换上Undertow即可:27. SpringBoot 切换内嵌Servlet容器_servlet容器_0327. SpringBoot 切换内嵌Servlet容器_servlet容器_04

 

运行:

27. SpringBoot 切换内嵌Servlet容器_tomcat_05

 

 可以看到 编程了 Undertow

 

尝试更换为Jetty:

27. SpringBoot 切换内嵌Servlet容器_spring_06

 

 

27. SpringBoot 切换内嵌Servlet容器_spring_07

27. SpringBoot 切换内嵌Servlet容器_servlet容器_08

所以 你以后自己写的EmbeddedServletContainerCustomizer Servlet容器 默认就会是你自己换的那个内嵌容器了.

 


作者:咸瑜​


举报

相关推荐

0 条评论