Tomcat is the default embedded server that comes with Spring Boot. As a result, we can run the application without having to worry about the server.However, depending on the conditions and requirements, we may require a different embedded server, such as Jetty or Undertow.
In this scenario, we need to notify Spring Boot not to use Tomcat as an embedded server, which we do in pom.xml.
Configure Jetty in Spring Boot
Adding Jetty is pretty straight forward, at first you need to exclude tomcat server as default embedded server and add Jetty.
<!-- Exclude tomcat dependency -->
<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>
<!-- Include jetty dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Configure Undertow embedded server in Spring Boot
Undertow configuration is similar as that of Jetty, at first you need to exclude tomcat server as default embedded server and add Undertow.
<!-- Exclude tomcat dependency -->
<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>
<!-- Include undertow dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
Conclusion
This post was short where we talked about how to add different embedded servers in Spring Boot applications.