Spring Boot Tutorial

Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)

Prerequisite (Spring Core Concepts)

Spring Boot Core

Spring Boot with REST API

Spring Boot with Database and Data JPA

Spring Boot with Kafka

Spring Boot with AOP

Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat

In the Spring Boot ecosystem, "starters" are a set of convenient dependency descriptors that allow developers to simplify their build configuration. Starters encapsulate common dependencies into single references. Let's look into the differences between spring-boot-starter-web and spring-boot-starter-tomcat.

spring-boot-starter-web:

  1. Purpose: This starter is used to build web applications, including RESTful APIs, using Spring MVC. It provides tools for creating web applications that can handle HTTP requests and responses.

  2. Dependencies: It bundles a variety of dependencies, which include:

    • Spring MVC (for web applications)
    • Jackson (for JSON support)
    • Validation API & Hibernate Validator (for bean validation)
    • Embedded Tomcat (as the default servlet container)
    • And other necessary libraries for developing web applications.
  3. Usage: When you want to create a Spring-based web application or RESTful service, you would include this starter. By including this starter, you get everything you need to quickly set up and run a web-based application.

spring-boot-starter-tomcat:

  1. Purpose: This starter provides an embedded Tomcat servlet container as the default. It's specifically focused on Tomcat as the application server.

  2. Dependencies: It primarily bundles:

    • Tomcat core libraries (for the embedded server functionality)
    • Tomcat WebSocket libraries (for WebSocket support)
  3. Usage: In most cases, you don't need to directly include this starter, as it's a transitive dependency of spring-boot-starter-web. However, in scenarios where you want to customize the embedded Tomcat version or if you're creating a non-web application but want an embedded Tomcat for some reason, you might add it explicitly.

In Summary:

  • spring-boot-starter-web is a broader starter that provides everything you need to create a web application, including the embedded Tomcat.
  • spring-boot-starter-tomcat, on the other hand, is more focused, only providing Tomcat-specific dependencies for embedding Tomcat in an application.

When you add spring-boot-starter-web to your project, you're implicitly getting spring-boot-starter-tomcat because the former includes the latter. However, there can be scenarios where you might want to exclude the default Tomcat (e.g., when you want to use Jetty or Undertow as your embedded server) or include it explicitly for customization.