依赖

接口测试类
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "Hello World!";
}
}
我们发现Spring-web中已经包含有Tomcat相关依赖
运行工程


通常情况下默认端口是8080,我们可以在application.properties修改相关配置
#修改端号
server.port=8081
#修改访问路径
server.servlet.context-path=/alvin
#配置 Tomcat URL 编码
server.tomcat.uri-encoding=UTF-8


更换服务
通常我们Spring-web依赖启动服务是Tomcat,也可以更改服务为jetty或者underTow等其他服务
更换为jetty服务
在依赖中用<exclusion>将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>
来源:CSDN
作者:Lukey Alvin
链接:https://blog.csdn.net/qq_44717317/article/details/104098954