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

Spring Boot allows developers to replace the default embedded server with another supported server by excluding the existing server dependency and adding the dependency of the desired server. This flexibility enables applications to use Tomcat, Jetty, or Undertow based on performance, deployment, or architectural requirements.

Key Points

Default Server in Spring Boot

When we add

spring-boot-starter-web

Spring Boot automatically includes

As a result, Tomcat starts automatically when the application launches.

How to Switch the Embedded Server?

The process involves two steps

1. Exclude the current server.

2. Add the new server dependency.

Switching from Tomcat to Jetty

Step 1: Exclude 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>

Step 2: Add Jetty

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

After startup

Embedded Jetty

will be used instead of Tomcat.

Switching from Tomcat to Undertow

Step 1: Exclude 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>

Step 2: Add Undertow

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

Spring Boot will automatically configure Undertow during startup.

How It Works Internally

Application Starts

|

Classpath Scanned

|

Tomcat Excluded

|

Jetty/Undertow Detected

|

Auto-Configuration Applied

|

Selected Server Starts

Spring Boot chooses the available server implementation and configures it automatically.

Example

Suppose a project initially uses

spring-boot-starter-web

Result

Embedded Tomcat Starts

After excluding Tomcat and adding

spring-boot-starter-jetty

Result

Embedded Jetty Starts

The application code remains unchanged.

Why Change the Embedded Server?

Common reasons include

Server Options

Tomcat

Jetty

Undertow

Benefits of Embedded Server Switching

Real-World Example

An organization standardizes all microservices on Undertow for lower memory usage.

Developers simply

1. Exclude Tomcat.

2. Add Undertow dependency.

Spring Boot automatically switches servers without requiring changes to controllers, services, or business logic.

Interview Tip

A concise interview answer is

To disable the default embedded server in Spring Boot, exclude its dependency from the project configuration. Then add the dependency of the desired server, such as Jetty or Undertow. Spring Boot's auto-configuration mechanism detects the new server on the classpath and automatically configures it without requiring application code changes.

Last updated: 11 November 2026

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

More Spring Boot - Level I interview questions

All Spring Boot - Level I questions