springboot引入spring-boot-starter-web,默认会引入tomcat。
所以引入jetty先要排除掉tomcat,然后添加jetty的依赖,如下所示:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
启动如下图所示:

测试类如下:
package com.edu.spring.springboot; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class AccountController { @RequestMapping("/hello") public String reg(){ return "hello Tom"; } }
浏览器输入:http://127.0.0.1:8080/hello 即可返回:hello Tom
原文:https://www.cnblogs.com/javasl/p/11918176.html