Quick revision
The short answer
In Maven, we exclude spring-boot-starter-tomcat from spring-boot-starter-web and add spring-boot-starter-jetty; Spring Boot detects which server is on the classpath and configures it, with no code change. WebFlux uses Reactor Netty by default, and it can also run on Tomcat or Jetty by swapping the starter in the same way. Spring Boot 4 removes Undertow support, so services using Undertow must move to Tomcat or Jetty when they upgrade; check the release notes.
What to remember
In this answer, we switched a Spring MVC application from Tomcat to Jetty in Maven by excluding spring-boot-starter-tomcat from the web starter and adding spring-boot-starter-jetty, and saw that Spring Boot picks the server from the classpath with no code change. We verified it with the startup log and the dependency tree, learned that WebFlux uses Reactor Netty by default and can run on Tomcat or Jetty, and noted that Spring Boot 4 removes Undertow support, so Undertow users must switch when they upgrade.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In Maven, we exclude spring-boot-starter-tomcat from spring-boot-starter-web and add spring-boot-starter-jetty; Spring Boot detects which server is on the classpath and configures it, with no code change. WebFlux uses Reactor Netty by default, and it can also run on Tomcat or Jetty by swapping the starter in the same way. Spring Boot 4 removes Undertow support, so services using Undertow must move to Tomcat or Jetty when they upgrade; check the release notes.
Why this question is asked
Spring Boot applications carry their web server inside the jar, and most teams never think about which one it is. But there are good reasons to switch: a company standard, a feature one server handles better, a security advisory, or an upgrade that drops a server altogether, as Spring Boot 4 does for Undertow. Interviewers ask this because it shows whether we understand how Boot chooses a server from the classpath, and the difference between the servlet and reactive stacks. In this answer, we will recap how the embedded server is chosen, make the switch in Maven, verify it, look at WebFlux and its default, and cover the Undertow change in Spring Boot 4.
1A Quick Recap of How Boot Chooses the Server
An embedded server is a web server that runs inside our application's process, started by Spring Boot, instead of a separate server we deploy a war file into. Spring Boot's auto-configuration looks at the classpath at startup: if it finds Tomcat's classes, it creates a Tomcat server; if it finds Jetty's, a Jetty server. There is no setting that names the server; the dependencies decide.
spring-boot-starter-web, the starter for Spring MVC, brings Tomcat through its dependency spring-boot-starter-tomcat. So switching means two things: removing Tomcat from the classpath and adding Jetty. If both were present, Spring Boot would still pick one in a fixed order, Tomcat first, so leaving Tomcat in place would make the change silently ineffective.
- Is it a servlet application?Spring MVC on the classpathYesLook for a servlet serverNoReactive: look for Reactor Netty, Tomcat or Jetty
- Tomcat classes present?spring-boot-starter-tomcatYesStart TomcatNoCheck for Jetty
- Jetty classes present?spring-boot-starter-jettyYesStart JettyNoNo server: startup fails or runs without web
3 steps in order. Play them, or step through them one at a time.
2Switching to Jetty in Maven
We add an exclusion to the web starter and a dependency on the Jetty starter. Versions come from Spring Boot's dependency management, so we do not write them.
Notice that nothing changes in the code or in most of the configuration. Properties under server.*, such as server.port, server.compression.enabled and server.ssl.*, apply to whichever server is running; server-specific ones live under server.tomcat.* or server.jetty.*, so any server.tomcat.* settings should be translated to their Jetty equivalents, such as server.jetty.threads.max, or removed. In Spring Boot 4 the web starter has been renamed, with spring-boot-starter-webmvc as the new name for the MVC starter; check the release notes for your version, the exclusion pattern stays the same.
3Verifying the Switch
Two quick checks confirm the change. The startup log names the server, and the dependency tree shows that no Tomcat jars remain, which matters because a library that pulls in tomcat-embed-core by another route would bring Tomcat back.
The exact logger names differ between versions, but the message always says which server started. Running the integration tests after the switch is worth it, because servers differ in small ways, such as default limits on header sizes and how they handle some malformed requests.
4WebFlux and Its Default Server
Spring WebFlux is the reactive web stack. It does not use the servlet blocking model and needs a server that supports non-blocking I/O. spring-boot-starter-webflux brings spring-boot-starter-reactor-netty, so Reactor Netty is the default, and it is the most common choice for reactive services.
WebFlux can also run on Tomcat or Jetty, through their non-blocking servlet support. The switch follows the same pattern: exclude spring-boot-starter-reactor-netty from the WebFlux starter and add spring-boot-starter-tomcat or spring-boot-starter-jetty. One caution: if both the MVC and WebFlux starters are on the classpath, Spring Boot builds a Spring MVC application, because MVC takes priority; spring.main.web-application-type=reactive forces the reactive stack.
| Stack | Starter | Default server | Alternatives |
|---|---|---|---|
| Spring MVC (servlet) | spring-boot-starter-web | Tomcat | Jetty; Undertow only before Boot 4 |
| Spring WebFlux (reactive) | spring-boot-starter-webflux | Reactor Netty | Tomcat, Jetty; Undertow before Boot 4 |
5Undertow and Spring Boot 4
Spring Boot 3.x supports Undertow as a third embedded server through spring-boot-starter-undertow. Spring Boot 4 drops it, because Undertow does not support the Servlet 6.1 baseline that Spring Framework 7 requires. Services that use Undertow must switch to Tomcat or Jetty as part of the upgrade, and the switch is the same exclusion-and-starter change we made above, plus translating any server.undertow.* properties. Check the Spring Boot 4 release notes for the exact details of your version, since support decisions can change between milestones.
6Follow-up questions
Why would a team choose Jetty over Tomcat?
Usually for a company standard or a specific feature, such as Jetty's handling of some HTTP/2 or WebSocket setups, or its smaller footprint for some workloads. For most applications both perform similarly, so the choice is about operations and familiarity rather than speed.
How do I do the same in Gradle?
Exclude the module from the web starter or globally, for example configurations.all { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' }, and add implementation 'org.springframework.boot:spring-boot-starter-jetty'. The detection at runtime is the same.
Can I customise the server in code?
Yes, with a WebServerFactoryCustomizer for the server's factory type, for example JettyServletWebServerFactory, which lets us set options that have no property. Such customisers are server-specific, so they must be updated when switching servers.
7Conclusion
In this answer, we switched a Spring MVC application from Tomcat to Jetty in Maven by excluding spring-boot-starter-tomcat from the web starter and adding spring-boot-starter-jetty, and saw that Spring Boot picks the server from the classpath with no code change. We verified it with the startup log and the dependency tree, learned that WebFlux uses Reactor Netty by default and can run on Tomcat or Jetty, and noted that Spring Boot 4 removes Undertow support, so Undertow users must switch when they upgrade.
Open with
Spring Boot picks the embedded server from the classpath, so switching is only a dependency change. spring-boot-starter-web pulls in spring-boot-starter-tomcat, so in Maven I add an exclusion for spring-boot-starter-tomcat on the web starter and add spring-boot-starter-jetty as a dependency, without versions, since Boot manages them.
Then, if they want more
No code changes. Generic server properties like server.port still apply, but anything under server.tomcat needs translating to the server.jetty equivalents. I verify it in two ways. The startup log should say Jetty started on port 8080, and mvn dependency:tree filtered on the Tomcat embed group should show nothing, in case another library brings Tomcat back.
Then I run the integration tests, since servers differ slightly in defaults like header size limits. For WebFlux, the reactive stack, the default server is Reactor Netty, because spring-boot-starter-webflux brings spring-boot-starter-reactor-netty. It can also run on Tomcat or Jetty with the same exclude-and-add pattern.
If both the MVC and WebFlux starters are present, Boot builds an MVC application unless I set the web application type to reactive. Finally, Spring Boot 4 removes Undertow support, because Undertow does not support the Servlet 6.1 baseline, so Undertow services have to move to Tomcat or Jetty during the upgrade.
I would check the release notes for the details, including the renamed web MVC starter.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4, Spring Boot 3, Spring Framework 7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you switch a Spring MVC application from Tomcat to Jetty in Maven, and which...": https://scrivio-interview-library.netlify.app/spring-boot/embedded-servers/d840caabdd/