Spring Boot determines which embedded server to use based on the dependencies available on the application's classpath. During startup, Spring Boot's auto-configuration mechanism scans the project dependencies and automatically configures the appropriate server.
Key Points: • Tomcat is the default embedded server in Spring Boot. • If Tomcat is excluded and another supported server dependency is added, Spring Boot automatically switches to that server. • This decision is made using Spring Boot's auto-configuration and conditional annotations.
Example: Suppose a project includes:
spring-boot-starter-web
Spring Boot automatically includes:
• Embedded Tomcat
As a result, the application starts with Tomcat without any additional configuration.
Server Selection Process:
Application Startup ↓ Classpath Scanning ↓ Check Available Server Dependencies ↓ Apply Auto Configuration ↓ Start Embedded Server
Supported Embedded Servers:
• Apache Tomcat (Default) • Jetty • Undertow
Default Behavior:
Dependency:
spring-boot-starter-web
Result: • Embedded Tomcat is configured automatically.
Using Jetty:
Step 1: Exclude Tomcat dependency.
Step 2: Add:
spring-boot-starter-jetty
Result: • Spring Boot starts Jetty instead of Tomcat.
Using Undertow:
Step 1: Exclude Tomcat dependency.
Step 2: Add:
spring-boot-starter-undertow
Result: • Undertow becomes the embedded server.
How Auto-Configuration Works:
Spring Boot uses:
• @EnableAutoConfiguration • Conditional Annotations • Classpath Detection
Example Conditional Logic:
If Tomcat classes exist: Configure Tomcat
Else If Jetty classes exist: Configure Jetty
Else If Undertow classes exist: Configure Undertow
This process happens automatically during application startup.
Why This Is Useful:
• Eliminates manual server configuration. • Simplifies deployment. • Makes server replacement easy. • Supports executable JAR deployment.
Real-World Example:
Microservices Application:
Order Service: • Uses Tomcat
Notification Service: • Uses Undertow for lightweight performance
Streaming Service: • Uses Jetty for specific tuning requirements
Each service can use the server best suited for its workload.
Interview Tip: A concise interview answer is: Spring Boot chooses the embedded server by inspecting the dependencies available on the classpath during startup. If Tomcat is present, it is configured by default. If Tomcat is excluded and Jetty or Undertow dependencies are added, Spring Boot automatically configures and starts the available server using its auto-configuration mechanism.