springboot替换tomcat

本文介绍了如何在Spring Boot应用中从默认的Tomcat服务器切换到Jetty。首先,你需要排除Tomcat依赖,然后引入Jetty的starter。由于Jetty9.4不支持Servlet4.0,因此需要覆盖Servlet API的版本。此外,还展示了如何通过设置`server.port=0`来扫描可用端口,避免冲突。
摘要由CSDN通过智能技术生成

switching to a different HTTP server, you need to exclude the default dependencies in
addition to including the one you need. To help with this process, Spring Boot provides a separate
starter for each of the supported HTTP servers.

<properties>
  <servlet-api.version>3.1.0</servlet-api.version>
</properties>
<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>

... 
The version of the Servlet API has been overridden as, unlike Tomcat 9 and
Undertow 2.0, Jetty 9.4 does not support Servlet 4.0.

To scan for a free port (using OS natives to prevent clashes) use server.port=0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值