添加 Undertow 依赖项
我们需要在这里做两件事:-
-
spring-boot-starter-tomcat
排除添加的默认依赖项spring-boot-start-web
- 添加
spring-boot-starter-undertow
依赖。
pom.xml
<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-undertow</artifactId>
</dependency>
build.gradle
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
}
implementation 'org.springframework.boot:spring-boot-starter-undertow'
}
而已。您已将 tomcat 替换为 Undertow 服务器。
应用程序启动日志
当您启动 Spring Boot 应用程序时,您将在日志中显示 Undertow 现在正在为您的 Web 应用程序提供服务:-
INFO c.e.demo.SpringBootDemoApplication : Starting SpringBootDemoApplication using Java 11.0.10 on Ashishs-MBP with PID 5166 (/Users/ashl/IdeaProjects/springboot-examples/springboot-config/build/classes/java/main started by ashl in /Users/ashl/IdeaProjects/springboot-examples/springboot-config)
DEBUG c.e.demo.SpringBootDemoApplication : Running with Spring Boot v2.5.0, Spring v5.3.7
INFO c.e.demo.SpringBootDemoApplication : No active profile set, falling back to default profiles: default
WARN io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
INFO io.undertow.servlet : Initializing Spring embedded WebApplicationContext
INFO w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 753 ms
INFO io.undertow : starting server: Undertow - 2.2.7.Final
INFO org.xnio : XNIO version 3.8.0.Final
INFO org.xnio.nio : XNIO NIO Implementation Version 3.8.0.Final
INFO org.jboss.threads : JBoss Threads version 3.1.0.Final
INFO o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port(s) 8080 (http)
INFO c.e.demo.SpringBootDemoApplication : Started SpringBootDemoApplication in 1.858 seconds (JVM running for 2.21)