Luca Stancapiano
Luca Stancapiano

Reputation: 19

change default web server on spring-boot 2.4.4

I'm working with Spring Boot 2.4.4 and I would change the default web server Tomcat to undertow orJHetty but I find it very difficult using both Gradle or Maven.

An old documentation exposes how do it but I'm sure all is changed because now tomcat, undertow and jetty configuration is embedded in the core library:

https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html

How do it in the 2.4.4 version?

Upvotes: 1

Views: 2473

Answers (2)

karthick kumar
karthick kumar

Reputation: 11

follow three steps to change the default web server, change configuration in pom.xml.

1.exclude the default web server.

2.Include the necessary web server.

3.Maven update.

For example,

Instead of this

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

Add this one

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

for the necessary server add the appropriate web server dependency.

Upvotes: 1

Nikolas
Nikolas

Reputation: 44418

There are no changes between the versions. This is well described right at the Spring Boot 2.4.4 Reference guide, right in 3.1. Use Another Web Server section. Basically, the change consists of two steps:

  1. Exclude embedded Tomcat server dependency from the spring-boot-starter-web artifact:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- Exclude the Tomcat dependency -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  1. Include your embedded server as a separate dependency instead:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

Just don't forget to notice the following quote from the reference guide in the very same section which might or might not be relevant to you:

The version of the Servlet API has been overridden as, unlike Tomcat 9 and Undertow 2.0, Jetty 9.4 does not support Servlet 4.0.

Upvotes: 3

Related Questions