在 Spring Boot 中配置嵌入式 Undertow 服務器

添加 Undertow 依賴項

我們需要在這里做兩件事:-

  1. spring-boot-starter-tomcat排除添加的默認依賴項spring-boot-start-web
  2. 添加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 現(xiàn)在正在為您的 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)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容