Spring Boot - Replace Tomcat With Jetty As the Embedded Server

Spring Boot web starter uses Tomcat as the default embedded server. If you’d like to change the embedded web server to Jetty instead, you’ll have to:

  1. Exclude Tomcat from web starter dependency, since it is added by default
  2. Add the Jetty dependency

Step 1: Exlude Tomcat

Find the following dependency in pom.xml:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Replace it with:

<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>

Step 2: Add Jetty

Add the following dependency to your pom.xml:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

That’s all. Launch your app and you should be good. Please note that there are some other starters e.g. ThymeLeaf that might pull in Tomcat by default. If you’re using one of these, please be sure to exlude Tomcat from all such dependencies.

Please leave your comments below and like on Facebook or follow on Twitter to stay up-to-date.

comments powered by Disqus