Spring Boot uses Embedded Tomcat as the default web server, but it can be replaced or customized with other embedded servers such as Jetty or Undertow based on application requirements such as performance, memory usage, or asynchronous processing capabilities.
Key Points: • Embedded Tomcat is the default server provided by spring-boot-starter-web. • Spring Boot allows replacing Tomcat with Jetty or Undertow with minimal configuration changes. • Customizing or replacing the server does not require changes to business logic or application code.
Example: A high-concurrency real-time application may prefer Undertow because of its lightweight and non-blocking architecture, while a traditional enterprise application may continue using Tomcat.
Replacing Embedded Tomcat:
Step 1: Exclude Tomcat dependency.
Step 2: Add the desired server dependency.
For Jetty:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>For Undertow:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>Spring Boot automatically detects the available server and configures it during application startup.
Comparison:
Tomcat: • Default embedded server. • Mature and widely used. • Suitable for most enterprise applications.
Jetty: • Lightweight and modular. • Faster startup time. • Suitable for microservices and cloud environments.
Undertow: • High-performance and non-blocking. • Lower memory consumption. • Ideal for high-concurrency applications.
Customizing Embedded Tomcat:
Even without replacing Tomcat, we can customize it using application properties.
Example:
server.port=9090
server.tomcat.max-threads=300
server.tomcat.accept-count=100Common Customizations:
• Change server port. • Configure thread pool size. • Enable compression. • Configure SSL certificates. • Adjust connection timeout settings.
Real-World Example:
An API Gateway handling thousands of requests per second may use Undertow for better throughput, while a standard business application may continue using Tomcat due to its maturity and stability.
Benefits of Embedded Servers:
• Simplified deployment. • No external application server installation required. • Easy containerization with Docker and Kubernetes. • Consistent behavior across environments.
Interview Tip: A concise interview answer is: Yes, Spring Boot allows replacing the default Embedded Tomcat server with Jetty or Undertow by excluding the Tomcat dependency and adding the desired server starter dependency. Spring Boot automatically configures the new server, making the transition seamless without requiring application code changes.