Replacing Tomcat with Undertow in Spring Boot: Configuration, Performance Comparison, and Benefits
This article explains how to replace Spring Boot's default embedded Tomcat container with Undertow, provides the necessary Maven configuration, compares their performance and memory usage, and highlights why Undertow is a superior choice for high‑concurrency Java web applications.
Spring Boot uses Tomcat as its default embedded servlet container, but it also supports Undertow, a high‑performance, lightweight web server.
Undertow, developed by Red Hat, offers non‑blocking NIO, full Servlet 3.1/4.0 support, WebSocket, and can be embedded directly into Java applications.
Key features of Undertow include high concurrency performance, Servlet 4.0 support, full WebSocket (JSR‑356) support, embedded operation without a separate container, flexible handler chains, and a small footprint consisting of two core JARs.
To switch Spring Boot from Tomcat to Undertow, remove the Tomcat starter dependency and add the Undertow starter dependency in 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>After rebuilding and starting the application, the embedded server changes to Undertow.
Benchmark tests on the same hardware show that Undertow achieves higher QPS and lower memory consumption than Tomcat under high concurrency, making it a better choice for performance‑critical services.
In conclusion, while Spring Boot can run with either Tomcat or Undertow, Undertow provides superior performance and resource efficiency for high‑traffic applications.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.