根据每个公司的不同习惯,有的时候需要切换spring boot的默认的Servlet 容器,比如我就比较青睐于Jetty,下面是我的替换的pom中d的配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
PS:为什么要强制不引用Tomcat容器,那是因为Tomcat的装载的顺序比较靠前,如果不排除的话,即使引入了jetty的starter,最终使用的容器还是Tomcat
SpringBoot切换Servlet容器至Jetty

本文介绍如何在SpringBoot项目中将默认的Tomcat容器更换为Jetty。通过在pom.xml文件中排除Tomcat依赖并引入Jetty启动器,实现Servlet容器的切换,避免Tomcat优先级导致的问题。
1040

被折叠的 条评论
为什么被折叠?



