• Home  / 
  • Spring Boot
  •  /  How to change the Spring Boot container – Tomcat to Undertow

How to change the Spring Boot container – Tomcat to Undertow

By Daniel Vladimirov / last month

In this tutorial we are going to look at how we can easily change our embedded servlet container in our Spring Boot web application. If you don’t have any source code to work on, I’m going to use the same application we created in the previous article, which you can check out here


For the time being Undertow seems to be the better choice performance wise, although tests show that the difference between all the servlet container options is rather miniscule. It’s better to choose a container based on your familiarity with it and its features, though there is a lot of overlap there as well.

Tomcat is the default embedded container (as of writing) in Spring Boot, so you don’t have to do anything special to start your application with Tomcat.

Starting our application, without any modifications, we see the following console output (cleared for brevity)

Tomcat initialized with port(s): 8080 (http)
Starting service [Tomcat] Starting Servlet Engine: Apache Tomcat/8.5.15
Initializing Spring embedded WebApplicationContext
Root WebApplicationContext: initialization completed in 1367 ms
Mapping servlet: ‘dispatcherServlet’ to [/] Tomcat started on port(s): 8080 (http)
Started Application in 2.397 seconds (JVM running for 2.75)

In order to change the container, we need to modify our POM file

We’ve added an exclusion to our spring-boot-starter-web and excluded the spring-boot-starter-tomcat dependency.

Then we added another dependency to introduce a different servlet container

<!– https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-undertow –>

This is all that is needed to change your servlet container. The method is also applicable if you want to use Jetty instead of Tomcat or Undertow.

Starting our application now gives a slightly different console output

Undertow started on port(s) 8080 (http)
Started Application in 2.137 seconds (JVM running for 2.475)


About the author

Daniel Vladimirov

Software engineer and founder of simplyprogram.com

Click here to add a comment

Leave a comment: