Last Updated on 19/08/2022

This tutorial will show you show to change Spring Boot embedded container from its default Tomcat, to an alternative Jetty or Undertow.
The project Spring Boot Starter Web ships with Spring MVC and a Tomcat embedded container that at build time, is packaged within the executable jar file of the standalone Spring Boot application, so everything you need to run the application including the web container itself, is included in that jar.
However, you may want to change Tomcat for another container of your choice by whatever it is the reason, so I will going to show the required steps.
Exclude Tomcat from Starter Web project
Your current Spring Boot Starter Web dependency might look like the following in your pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
So first, you have to add an exclusion
for the Tomcat that is shipped with it:
<!-- Spring Boot Starter Web MVC excluding 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>
Now that you have excluded Tomcat, let’s move to how to add the new container.
Add Jetty dependency
All you need to do now is to add the Jetty dependency in your pom.xml
like the following:
<!-- Jetty instead of Tomcat --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
Or add Undertow dependency
However, if you prefer Undertow instead of Jetty and Tomcat, just add the Undertow dependency in your pom.xml
file:
<!-- Undertow instead of Tomcat and Jetty --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
Now, your new container is going to be used on the next startup:

I hope it helps.
Cya!
i clean but it is not working running with tomcat only
I have changed to Undertow, but Tomcat is still running…
Hi Arilson. It sounds like your project hasn’t updated its dependencies. If you perform a
mvn clean install
and try again, it should work.Hi Bruno, congratulations! This is a short and very useful tip!!!
Thank you!
Thank you! I am glad you liked it =]