skip to content

Server selection

Tomcat is the servlet default, Jetty or Undertow are a starter exclusion away, and WebFlux runs on Netty — the application type decides. Interviewers ask why you would ever switch, and 'because someone said it is faster' is not the answer.

part ofSpring Frameworkread it →
on this pageshow

questions

5

What is the default embedded server in a Spring Boot servlet web application, and how does it get there?

level: juniorimportance: must knowfreq 70%

answer

  1. starter-web -> starter-tomcat transitive
  2. TomcatServletWebServerFactory auto-config
  3. embedded = inside JVM, fat JAR
  4. default port 8080
  5. servlet stack default only

basics

~10 s

Embedded Apache Tomcat. When you add spring-boot-starter-web, it transitively pulls in spring-boot-starter-tomcat, so Spring Boot auto-configures and starts an embedded Tomcat on port 8080 by default.

solid answer

~40 s

For a servlet-stack web app (spring-boot-starter-web), the default is embedded Apache Tomcat. The web starter depends on spring-boot-starter-tomcat, which puts Tomcat on the classpath; ServletWebServerFactoryAutoConfiguration then detects it and creates a TomcatServletWebServerFactory, so the app runs a self-contained Tomcat inside the JVM — no external server or WAR deployment needed. It listens on port 8080 unless server.port says otherwise. "Embedded" means the servlet container is a library bundled in your fat JAR and started programmatically in main(), rather than you deploying a WAR into a standalone Tomcat/JBoss. You can override the default by excluding spring-boot-starter-tomcat and adding the Jetty or Undertow starter instead.

code

xml · 8 lines
xml
<!-- Adding this one starter gives you embedded Tomcat by default -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring-boot-starter-web transitively includes spring-boot-starter-tomcat.
     ServletWebServerFactoryAutoConfiguration then builds a
     TomcatServletWebServerFactory and starts Tomcat on port 8080. -->

go deeper

for a junior

Know it's embedded Tomcat on 8080, pulled in by spring-boot-starter-web.

for a middle

Explain the transitive dependency chain and that auto-config builds the factory.

for a senior

Name TomcatServletWebServerFactory / ServletWebServerFactoryAutoConfiguration and the classpath conditions.

for a principal

Frame it as a classpath-driven convention and contrast with reactive/Netty and WebApplicationType inference.

## What an embedded server is **Embedded server** means the HTTP/servlet container runs *inside* your application's JVM process, started from your `main()` method, rather than you packaging a WAR and deploying it into a separately installed application server. Spring Boot's signature move is the "fat JAR" (a.k.a. executable/über JAR): one runnable `.jar` that contains your code, all dependencies, *and* the web server. ## How Tomcat becomes the default 1. When you add the starter `org.springframework.boot:spring-boot-starter-web`, Maven/Gradle transitively pulls in `spring-boot-starter-tomcat`, which brings Tomcat's `tomcat-embed-core` jar onto the classpath. 2. At startup, Spring Boot auto-configuration — specifically `ServletWebServerFactoryAutoConfiguration` and its nested `EmbeddedTomcat` configuration — sees the Tomcat classes on the classpath (via `@ConditionalOnClass`) and no other `ServletWebServerFactory` bean defined, so it creates a `TomcatServletWebServerFactory` bean. 3. That factory builds and starts the embedded Tomcat when the `ServletWebServerApplicationContext` refreshes. Default port is **8080** (change with `server.port`). ## Why Tomcat specifically It is the most battle-tested, widely deployed servlet container; Spring Boot picks it as the safe default. It implements the Jakarta Servlet API (formerly javax.servlet), so it works with the blocking, thread-per-request servlet programming model — Spring MVC (`@Controller`, `DispatcherServlet`). ## Key gotcha — SERVLET vs REACTIVE - The Tomcat default applies to the *servlet* stack (Spring MVC). - If instead you use `spring-boot-starter-webflux` (reactive stack), the default is **Netty**, not Tomcat. The choice is driven by the `WebApplicationType` Spring Boot infers from the classpath. ## When to keep the default Almost always for MVC apps. Only swap it out for a specific reason (async performance, footprint, ops standardization). **Terms defined:** - *Servlet container* = software implementing the Servlet spec (Tomcat/Jetty/Undertow). - *Auto-configuration* = Boot's conditional beans that configure the app based on what's on the classpath. - *Starter* = a curated dependency bundle.

  • What class actually creates the embedded Tomcat, and what condition triggers it?
    ServletWebServerFactoryAutoConfiguration (nested EmbeddedTomcat config) creates a TomcatServletWebServerFactory bean, gated by @ConditionalOnClass on Tomcat classes and no user-defined ServletWebServerFactory bean present.
  • Is Tomcat still the default if you use spring-boot-starter-webflux?
    No. WebFlux is the reactive stack; its default embedded server is Netty (Reactor Netty), not Tomcat.

  • Thinking you must install and deploy a WAR into an external Tomcat — Boot embeds it
  • Saying the default is Jetty or Netty for a plain MVC app
  • Believing the server is configured by XML rather than auto-configuration

context

open as a page

How do you switch a Spring Boot servlet app from Tomcat to Jetty or Undertow?

level: middleimportance: must knowfreq 60%

basics

~10 s

Exclude spring-boot-starter-tomcat from spring-boot-starter-web, then add spring-boot-starter-jetty (or spring-boot-starter-undertow). Boot's auto-configuration detects the new server on the classpath and uses it instead.

open as a page

What is WebApplicationType, how does Spring Boot infer it, and how does it govern which server (if any) starts?

level: seniorimportance: should knowfreq 40%

basics

~20 s

WebApplicationType is an enum (SERVLET, REACTIVE, NONE) that tells Spring Boot which kind of application context and web server to create. Boot infers it from the classpath: servlet classes -> SERVLET (Tomcat), only reactive/WebFlux -> REACTIVE (Netty), no web classes -> NONE (no server).

open as a page

For a Spring WebFlux (reactive) application, which embedded server runs by default and why is it different from the servlet stack?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Reactor Netty. WebFlux is a non-blocking, reactive stack that doesn't use the Servlet API, so it can't run on a servlet container's thread-per-request model. Netty's event-loop model fits reactive back-pressure; spring-boot-starter-webflux includes it by default.

open as a page

As an architect, how would you decide among Tomcat, Jetty, Undertow, and Netty for a Spring Boot service?

level: principalimportance: nice to knowfreq 28%

basics

~20 s

First decide the programming model: blocking MVC -> a servlet container (Tomcat/Jetty/Undertow); non-blocking WebFlux -> Netty. Among servlet containers, keep Tomcat unless you have a measured reason (footprint, throughput, WebSockets, ops standardization) to pick Undertow or Jetty.

open as a page