Replacing Tomcat with Undertow in Spring Boot: Configuration, Features, and Performance Comparison
This article explains how to replace Spring Boot's default embedded Tomcat with the high‑performance Undertow server, provides step‑by‑step Maven dependency changes, outlines Undertow's advantages, and presents benchmark results showing superior throughput and lower memory usage for high‑concurrency applications.
Spring Boot uses Tomcat as its default embedded servlet container, but Undertow offers better performance and lower memory consumption. This guide shows how to switch from Tomcat to Undertow and why it may be advantageous for high‑concurrency systems.
1. Spring Boot's Tomcat Container
Spring Boot is a popular Java web framework that embeds Tomcat by default, simplifying the creation of web services without external XML configuration.
2. Setting Up Undertow in Spring Boot
Undertow is a flexible, high‑performance web server written in Java, supporting both blocking and non‑blocking I/O, and fully compatible with Servlet 3.1. It can be used as a drop‑in replacement for Tomcat.
What is Undertow? It is an open‑source project from Red Hat, the default server for WildFly, designed for embedded use with an easy‑to‑use builder API.
Key Features High performance under load Servlet 4.0 support Full WebSocket support (JSR‑356) Embedded, no external container required Flexible handler chain configuration Lightweight, consisting of only two core JARs
To use Undertow, modify the Maven dependencies 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>After updating the dependencies and restarting the application, the embedded server will be Undertow.
3. Tomcat vs. Undertow: Performance Comparison
Benchmarks on identical hardware show that Undertow achieves higher QPS and lower memory usage than Tomcat under the same request load, thanks to its non‑blocking architecture and efficient connection handling.
In high‑concurrency scenarios, Undertow consistently outperforms Tomcat, making it the preferred choice for performance‑critical services.
4. Conclusion
Both Tomcat and Undertow can serve HTTP requests in Spring Boot, but Undertow provides superior throughput and memory efficiency for high‑traffic applications. Switching to Undertow can significantly improve system performance.
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.