Spring Boot exclude Tomcat

You can use Spring Boot without embedded Tomcat web server if you don’t need it. Just exclude embedded Tomcat from Spring Boot Web Starter (spring-boot-starter-web).

Spring Boot Starter Web with Tomcat

Exclude Tomcat from Spring Boot By default Spring Boot Starter Web contains embedded Tomcat. That’s cool. In most cases it’s very convenient - you don’t need to worry about having Tomcat web server in you Spring Boot application - it’s already there.

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

Spring Boot without Tomcat

Sometimes you don’t need Tomcat to be a part of your Spring Boot applications and you want to have Spring Boot without Tomcat. In this case you have to exclude Tomcat from Spring Boot. So we should make Spring Boot exclude Tomcat as a dependency.

To exclude Tomcat from Spring Boot just add an exclusion block to the Spring Boot Starter Web dependency and at the build time Maven will exclude Tomcat from Spring Boot.

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>

You can use that approach to exclude Tomcat from Spring Boot and also for any other exclusions


You may also find these posts interesting: