Configure Spring Boot to use Undertow Web server

By default, Spring boot uses Tomcat as embedded Web server. There are, however, other available Web servers in case you need some specific features. In this tutorial we will learn how to use Undertow as Web Server.

Add spring-boot-starter-undertow dependency

You will need to update pom.xml and add dependency for spring-boot-starter-undertow. Also, you will need to exclude default added spring-boot-starter-tomcat dependency as follows:

<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>

If you are using Gradle as build tool, the same result can be achieved using:

configurations { 
    compile.exclude module: "spring-boot-starter-tomcat" 
} 
dependencies { 
    compile("org.springframework.boot:spring-boot-starter-web:2.1.0.RELEASE") 
    compile("org.springframework.boot:spring-boot-starter-undertow:2.1.0.RELEASE") 
}

 With this configuration in place, you should be able to switch to Undertow Web Server

Verifying that Spring Boot uses Undertow

When you start your Spring Boot application, look for log entries that mention Undertow. You should see messages similar to the following:

2024-08-22 12:02:57.123  INFO 12345 --- [           main] io.undertow                              : starting server: Undertow - 2.2.14.Final
2024-08-22 12:02:57.456  INFO 12345 --- [           main] org.xnio                                 : XNIO version 3.8.0.Final
2024-08-22 12:02:57.789  INFO 12345 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.8.0.Final
2024-08-22 12:02:58.012  INFO 12345 --- [           main] io.undertow                              : starting server: Undertow - 2.2.14.Final
2024-08-22 12:02:58.345  INFO 12345 --- [           main] org.springframework.boot.web.embedded.undertow.UndertowWebServer : Undertow started on port(s) 8080 (http)

If the default logs are not sufficient, you can enable more detailed logging for Undertow by adding the following configuration to your application.properties or application.yml:

logging.level.io.undertow=DEBUG
logging.level.org.xnio=DEBUG

Finally, if you want to configure Undertow server, check the following article: Configuring Undertow in Spring Boot Applications

Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon