Skip to content

Change Spring Boot embedded container

Last Updated on 19/08/2022

Change Spring Boot embedded container logo


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:

Spring Boot starting with Jetty

I hope it helps.
Cya!

5 thoughts on “Change Spring Boot embedded container”

Leave a Reply

Your email address will not be published. Required fields are marked *