springboot更换web容器
时间: 2023-10-13 16:27:56 浏览: 87
Spring Boot默认使用Tomcat作为web容器,但也支持使用其他web容器,如Jetty和Undertow。
1. 更换为Jetty
在pom.xml中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
```
在application.properties中添加:
```
server.port=8080
server.servlet.context-path=/
```
启动应用,可以看到控制台输出:
```
Using embedded Jetty server
```
2. 更换为Undertow
在pom.xml中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
```
在application.properties中添加:
```
server.port=8080
server.servlet.context-path=/
```
启动应用,可以看到控制台输出:
```
Using embedded Undertow server
```
注意:如果同时添加了Jetty和Undertow的依赖,Spring Boot会默认使用Jetty。如果想使用Undertow,需要在pom.xml中排除Jetty的依赖。
阅读全文
相关推荐


















