Spring Boot provides built-in embedded web servers that allow applications to run independently without requiring deployment to an external application server. These servers are packaged with the application and start automatically when the application launches. By default, Spring Boot uses Apache Tomcat as its embedded server.
Key Points: • Spring Boot supports multiple embedded web servers. • Apache Tomcat is the default embedded server. • Developers can easily switch to Jetty or Undertow if needed. • Embedded servers simplify deployment and application management. • Applications can run directly using a JAR file without installing a separate server.
Why Are Embedded Servers Important?
In traditional Java web applications:
• Applications are packaged as WAR files. • They must be deployed to an external server. • Server installation and configuration are required.
Examples:
• Apache Tomcat • JBoss • WebLogic • WebSphere
Spring Boot simplifies this process by embedding the server inside the application itself.
Application | Embedded Server | Ready to Run
Run Command:
java -jar application.jar
No separate server installation is required.
Embedded Servers Supported by Spring Boot
1. Apache Tomcat (Default)
Tomcat is the default embedded server used by Spring Boot.
Features:
• Lightweight • Stable • Widely adopted • Excellent Spring integration
Dependency:
spring-boot-starter-web
When this starter is added, Tomcat is automatically included.
2. Jetty
Jetty is an alternative embedded web server.
Features:
• Lightweight • High performance • Efficient resource utilization
Often used in:
• Microservices • Cloud-native applications
3. Undertow
Undertow is a high-performance web server developed by Red Hat.
Features:
• Non-blocking architecture • Low memory consumption • High throughput
Often preferred for:
• High-concurrency applications • Performance-sensitive systems
How to Change the Default Server?
By default:
spring-boot-starter-web
includes Tomcat.
To use Jetty:
Exclude Tomcat and add:
spring-boot-starter-jetty
Example:
<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-jetty
</artifactId>
</dependency>Similarly, Undertow can be used by adding:
spring-boot-starter-undertow
Example: Suppose you create a REST API using:
spring-boot-starter-web
When the application starts:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(
Application.class,
args);
}
}Spring Boot automatically:
• Starts Tomcat • Opens the configured port • Deploys all REST endpoints
No external deployment is required.
Comparison of Embedded Servers
Tomcat
• Default server • Most commonly used • Excellent Spring support
Jetty
• Lightweight • Fast startup • Suitable for microservices
Undertow
• High performance • Non-blocking I/O • Low memory usage
Benefits of Embedded Servers
• Simplified deployment • Faster application startup • Easier development and testing • Portable applications • Better support for microservices architecture
Real-World Example
In a microservices environment:
Each service can be packaged as:
application.jar
When deployed:
• The embedded server starts automatically. • No dedicated application server is required. • Services can be deployed independently.
This is one of the major reasons Spring Boot became popular for cloud-native and microservice-based architectures.
Interview Tip: A concise interview answer is:
"Spring Boot supports embedded servers such as Apache Tomcat, Jetty, and Undertow. By default, Spring Boot uses Apache Tomcat when the spring-boot-starter-web dependency is included. These embedded servers allow applications to run as standalone JAR files without requiring deployment to an external application server."