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.
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.
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>
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!
This guide will show you how to create a Python function decorator with a few…
This guide will show you how to fix the error Got permission denied while trying…
This guide will show you how to create a Python virtual environment on Intellij IDEA…
This tutorial will quickly show you how to to find and kill processes on Linux,…
This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…
I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…
View Comments
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 =]