🏠Spring BootJetty with Spring Boot – Replacing tomcat with Jetty

Jetty with Spring Boot – Replacing tomcat with Jetty

Let’s learn how to change the default tomcat server with a jetty server in Spring boot with detailed instructions.

Tomcat and Jetty are the most known web servers in Java. They both have identical features and have the same set of features to offer. Even though I personally prefer tomcat, there are ways to update your spring boot application to use Jetty.

To replace tomcat with jetty, you need to follow these steps.

  1. Remove tomcat starter from spring-boot-starter-web
  2. Add jetty starter
  3. Adjust application.properties for any server.tomcat.* entries( if available ).

To remove the tomcat starter from your project, simply add an exclusion to the web dependency. And to add jetty support, just add the org.springframework.boot:spring-boot-starter-jetty dependency.

</dependency>Code language: HTML, XML (xml)

Even though jetty and tomcat do the same thing, under the hood they may be written/configured differently. For this reason, the configuration that you have placed for the tomcat may not work for the jetty.

For example, the below snippets set the maximum and the minimum number of threads for handling the web requests.

#Sample server Configuration for TOMCAT
server.tomcat.accept-count=100Code language: Properties (properties)
#Sample server Configuration for JETTY
server.jetty.threads.acceptors=100Code language: Properties (properties)

As you can see, the settings don’t match the exact names. But they are equivalent and you should handle these on switching between tomcat and jetty. But it is most likely that you never configured tomcat.

With the above completed, let us start our application.

spring boot running with jetty

As you can see, our application starts using Jetty as the embedded server.

Similar Posts

Leave a Reply

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