Open In App

Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat

Improve
Improve
Like Article
Like
Save
Share
Report

Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework and making a production-ready application in it takes very little time. Following are some of the features of Spring Boot:

  • It allows avoiding heavy configuration of XML which is present in spring
  • It provides easy maintenance and creation of REST endpoints
  • It includes embedded Tomcat-server
  • Deployment is very easy, war and jar files can be easily deployed in the tomcat server

Spring Boot Starter Web

It is mainly used for building web applications that include RESTful applications using Spring MVC. It uses Tomcat as the default embedded container. It has two important features:

  • It is compatible with web development.
  • It can be auto-configured.

We need to add the following dependency in the pom.xml file for Spring Boot Starter Web:

XML




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


It uses Spring MVC, REST, and Tomcat as a default embedded server. The single spring-boot-starter-web dependency can pull in all dependencies related to web development. It also reduces the count of build dependency. The spring-boot-starter-web mainly depends on the following:

  • org.springframework.boot:spring-boot-starter
  • org.springframework.boot:spring-boot-starter-tomcat
  • org.springframework.boot:spring-boot-starter-validation
  • com.fasterxml.jackson.core:jackson-databind
  • org.springframework:spring-web
  • org.springframework:spring-webmvc

By default, the spring-boot-starter-web contains the below tomcat server dependency given:

XML




<dependency>  
  <groupId>org.springframework.boot</groupId>  
  <artifactId>spring-boot-starter-tomcat</artifactId>  
  <version>2.0.0.RELEASE</version>  
  <scope>compile</scope>  
</dependency>


The spring-boot-starter-web auto-configures the below things required for the web development:

  • Dispatcher Servlet
  • Error Page
  • Embedded servlet container
  • Web JARs for managing the static dependencies

Spring Boot also supports Jetty Server and Undertow Server. They are embedded web servers. We can also exclude spring-boot-starter-tomcat from spring-boot-starter-web as follows:

XML




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


Spring Boot Starter Tomcat

While the spring-boot-starter-tomcat has everything related to the Tomcat server. It has

  • core
  • el
  • logging
  • WebSocket

It has the below dependencies

XML




<dependency>  
  <groupId>org.apache.tomcat.embed</groupId>  
  <artifactId>tomcat-embed-core</artifactId>  
  <version>8.5.23</version>  
  <scope>compile</scope>  
</dependency>  
<dependency>  
  <groupId>org.apache.tomcat.embed</groupId>  
  <artifactId>tomcat-embed-el</artifactId>  
  <version>8.5.23</version>  
  <scope>compile</scope>  
</dependency>  
  <dependency>  
  <groupId>org.apache.tomcat.embed</groupId>  
  <artifactId>tomcat-embed-websocket</artifactId>  
  <version>8.5.23</version>  
  <scope>compile</scope>  
</dependency>


Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat

Spring Boot Starter Web

Spring Boot Starter Tomcat

Spring Boot Starter Web is used for building RESTful applications using Spring MVC. Spring Boot Starter Tomcat is the default embedded container for Spring Boot Starter Web. 
We cannot exclude it while using web services. We can exclude it when we want to use another embedded container.
It also supports Jetty Server and Undertow Server. It acts as an embedded web server.
It auto-configures Dispatcher Servlet, Error Page, Embedded servlet container, and Web JARs for managing the static dependencies for web development. It has a core, el. logging, WebSocket.
It contains spring web dependencies. It contains everything related to an embedded tomcat server.
It auto-configures the features used for web development. It is used as the default embedded container.


Last Updated : 11 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads