Replacing Tomcat with Undertow in Spring Boot: Benefits, Configuration, and Performance Comparison
This article explains how to replace Spring Boot's default embedded Tomcat with Undertow, detailing the necessary Maven dependencies, configuration steps, and performance and memory usage comparisons that demonstrate Undertow's advantages for high‑concurrency Java backend applications.
Spring Boot uses Tomcat as its default embedded servlet container. For high‑concurrency scenarios, Undertow offers better performance and lower memory consumption.
1. Tomcat in Spring Boot
Spring Boot is a popular Java web framework that simplifies creating web services. Its default embedded container is Tomcat, which runs the application out of the box.
2. Introducing Undertow
Undertow is a flexible, high‑performance web server written in Java. It supports both blocking and non‑blocking I/O, Servlet 3.1, WebSocket, and is the default server for WildFly.
High performance under load
Supports Servlet 4.0
Full WebSocket support (JSR‑356)
Embedded‑only, no external container required
Modular and lightweight
3. Switching from Tomcat to Undertow
Remove the Tomcat starter from the Maven/Gradle dependencies and add the Undertow starter.
<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 will be Undertow.
4. Performance & Memory Comparison
Benchmark tests on the same hardware show that Undertow achieves higher QPS and lower memory usage than Tomcat under identical request loads.
5. Conclusion
For high‑concurrency Java backend services, replacing Tomcat with Undertow can significantly improve throughput and reduce resource consumption, making Undertow the preferred choice.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn 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.