How does Spring Boot decide which embedded server to use if multiple options are available in the classpath?

Spring Boot automatically selects an embedded web server based on the server implementation available on the application's classpath. By default, Tomcat is chosen because it is included in the spring-boot-starter-web dependency. If multiple server implementations are present, Spring Boot follows its auto-configuration rules and the dependency configuration to determine which server should be initialized.

Key Points

Default Behavior

When we add

spring-boot-starter-web

Spring Boot automatically includes

As a result, Tomcat becomes the default server.

Example

spring-boot-starter-web

|

Embedded Tomcat Added

|

Tomcat Starts

|

Application Ready

How Spring Boot Chooses the Server

During startup

Application Starts

|

Classpath Scanning

|

Server Dependencies Detected

|

Auto-Configuration Applied

|

Selected Server Starts

Spring Boot checks which server implementation libraries are available and applies the corresponding auto-configuration.

Common Embedded Servers

These servers can be used interchangeably depending on project requirements.

Using Jetty Instead of Tomcat

<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>

Now Spring Boot starts Jetty instead of Tomcat.

Using Undertow

<dependency>
    <groupId>
        org.springframework.boot
    </groupId>
    <artifactId>
        spring-boot-starter-undertow
    </artifactId>
</dependency>

Spring Boot will use Undertow when Tomcat is excluded.

What Happens if Multiple Servers Are Present?

Having multiple embedded server implementations on the classpath is not recommended.

Example

both included together.

This can lead to

Best practice is to keep only one embedded server dependency active.

Example

Suppose a project includes

spring-boot-starter-web

Since this starter already contains Tomcat, Spring Boot automatically starts:

Embedded Tomcat

and exposes the application on

http://localhost:8080

If Tomcat is removed and Jetty is added, Spring Boot automatically starts Jetty instead.

Benefits of Embedded Server Auto-Configuration

Real-World Example

A company develops multiple microservices

Most services use the default Tomcat server.

For high-performance workloads, one service may switch to Undertow simply by replacing the dependency, without changing application code.

Interview Tip

A concise interview answer is

Spring Boot selects the embedded server based on the server libraries available on the classpath. By default, spring-boot-starter-web includes Tomcat, so Tomcat is used automatically. If Tomcat is excluded and Jetty or Undertow is added, Spring Boot's auto-configuration mechanism detects the available server and starts it instead.

Last updated: 16 July 2026

Previous question: Which embedded servers does Spring Boot support, and which one is the default?

Next question: How do you disable the default embedded server in Spring Boot and use a different one?

More Spring Boot - Level I interview questions

All Spring Boot - Level I questions