Introduction

Spring Boot web starter uses Tomcat as the default embedded servlet container or Tomcat is the default embedded server. In this example we will see how to use Jetty instead of Tomcat in Spring Boot application.

Configurations

Generally we need to exclude the Tomcat server and use the Jetty starter in the dependency either in maven pom.xml file or gradle build.gradle file.

Maven based Configuration

If you use maven based Spring Boot application then do the Tomcat exclusion from your web starter as shown below:

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

Then add the Jetty started dependency as shown below:

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

Gradle based Configuration

If you use gradle based Spring Boot application then do the Tomcat exclusion from your web starter in build.gradle script as shown below:

compile("org.springframework.boot:spring-boot-starter-web") {
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' 
}

Then add the Jetty started dependency as shown below:

compile("org.springframework.boot:spring-boot-starter-jetty")

So we have seen how to use Jetty instead of Tomcat in Spring Boot application.

Thanks for reading.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

Leave a Reply

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