Moving from Tomcat to Jetty in your Spring Boot Application

Spring Boot does include some sensible defaults but it will not stand in your way.

I love getting questions from students because it gives me a great idea of the real world problems people are trying to solve. Today’s question comes from a student in my Spring Boot Introduction Course and has to do with using something other than the default. 

When I start a new Spring Boot Project and I include the web dependency I get Tomcat as the default servlet container. If I want to change that to something else like Jetty can I?

Moving from Tomcat to Jetty

The great thing about Spring Boot is that while it comes with some sensible defaults to get you up and running it doesn’t stand in your way if you need to change something. The answer to this question is Yes and in this short tutorial, we will look at how you can do this.

Replacing Tomcat with Jetty

If we create a new Spring Boot project and select web as a dependency the default servlet container is going to be Tomcat. 

The reason we know this is because if you dive into the spring-boot-starter-web dependency you will see the following dependencies declared. 

The first thing we need to do is remove the Tomcat dependency. We are going to do this in the starter dependency itself so we need some way of doing this in our Maven POM. Luckily we have a way to exclude a dependency using an exclusions block. 

Now that we have excluded Tomcat we can add our Jetty dependency. 

If you go ahead and run the application you will see in the console that we are indeed now running on Jetty. 


I hope this really helps drive home a point about Spring Boot. There are conventions and defaults that help us quickly and easily stand up a new Spring Application. Just because this is the default though doesn’t mean that we can change something to fit our needs. 

Question: What problems are you facing in your Spring Applications? 

Hi, I’m Dan Vega. I am a Software Engineer living just outside of one of my favorite places in the world, Cleveland, Ohio. I am a self-taught programmer who firmly believes that you can accomplish anything in this life if you put your mind to it, roll up your sleeves and are willing to put in the work.

I have been writing software for over 18+ years now and I use my knowledge, passion, and influence to help other developers achieve their goals. I teach online and currently, have over 30,000 students.

When I am not writing software, I have a number of things that really keep me busy. I love to read books, listen to podcasts and watch online courses. I have a real thirst for knowledge and it consumes me every single day of the week. I also love to run & lift heavy weights which keep me balanced throughout the week.

Please note: I reserve the right to delete comments that are offensive or off-topic.