添加 Undertow 依賴項(xiàng)
我們需要在這里做兩件事:-
-
spring-boot-starter-tomcat
排除添加的默認(rèn)依賴項(xiàng)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 服務(wù)器匪燕。
應(yīng)用程序啟動(dòng)日志
當(dāng)您啟動(dòng) Spring Boot 應(yīng)用程序時(shí)娜谊,您將在日志中顯示 Undertow 現(xiàn)在正在為您的 Web 應(yīng)用程序提供服務(wù):-
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)