A2oz

How to Change Embedded Tomcat Server in Spring Boot?

Published in Spring Boot 2 mins read

You can't directly replace the embedded Tomcat server in Spring Boot. Spring Boot's embedded Tomcat server is tightly integrated into the framework. However, you can achieve similar functionality by using a different embedded server like Jetty or Undertow.

Using Jetty:

  1. Add Dependency: Include the Jetty dependency in your pom.xml or build.gradle file.
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
  2. Remove Tomcat Dependency: If you have the Tomcat dependency, remove it.
  3. Run Application: Run your Spring Boot application. It will now use Jetty as the embedded server.

Using Undertow:

  1. Add Dependency: Include the Undertow dependency in your pom.xml or build.gradle file.
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>
  2. Remove Tomcat Dependency: If you have the Tomcat dependency, remove it.
  3. Run Application: Run your Spring Boot application. It will now use Undertow as the embedded server.

Additional Considerations:

  • Configuration: You can configure the embedded server using application properties or @Configuration classes.
  • Performance: Each server has its own strengths and weaknesses. Choose the server that best suits your application's requirements.

Remember, changing the embedded server might affect your application's behavior, so thoroughly test your application after switching.

Related Articles