spring-boot-starter-tomcat vs spring-boot-starter-web
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Spring Boot is known for its ability to simplify the development process of Java web applications by providing a comprehensive suite of features and integrations. Two of the popular starters in the Spring Boot ecosystem are `spring-boot-starter-tomcat` and `spring-boot-starter-web`. Understanding the distinctions between these two can help developers make informed decisions based on the requirements of their project.
Overview of Spring Boot Starters
Spring Boot starters are a way to easily include dependencies needed for a particular functionality in your application. When you include a starter in your `pom.xml` (for Maven) or `build.gradle` (for Gradle), it automatically pulls in a set of transitive dependencies that provide the necessary services.
spring-boot-starter-web
Description
`spring-boot-starter-web` is a starter for building web applications, including RESTful services, using Spring MVC. By default, it uses Tomcat as the embedded container but can be swapped to other containers like Jetty or Undertow if required.
Key Components
- Spring MVC: Facilitates the development of web applications with the Model-View-Controller design pattern.
- Embedded Tomcat (Default): Provides HTTP server capabilities.
- Jackson: For JSON binding.
- Validation and Binding: Support for validating inputs and performing data binding.
- Spring Web: Core capabilities for web applications.
Usage
To use `spring-boot-starter-web` in your Spring Boot project, add the following to your `pom.xml`:
- Embedded Tomcat: The core library for the Tomcat server.
- Jasper: JSP support, especially useful if you're using JSP as a view technology.
- Selective Dependency: Allows using Tomcat alone without Spring MVC.
- Project Requirements: Assess if you need a comprehensive web framework (`spring-boot-starter-web`) or just the embedded server capabilities (`spring-boot-starter-tomcat`).
- Customization: If you require customizations specific to Tomcat, such as altering the thread pool, access logs, or specific connector settings, using `spring-boot-starter-tomcat` directly may be beneficial.
- Dependency Management: Using `spring-boot-starter-web` ensures that the common dependencies for a web application are all included, simplifying dependency management.
Related reading
- Spring-Boot and Kafka How to handle broker not available?
- Spring-boot application-test.properties
- spring-boot application without a datasource
- Spring-boot automatically import applicationContext.xml?
- spring-boot default log location
- Spring-boot default profile for integration tests
- Spring-boot default profile for integration tests
- Spring-Boot execute data.sql in one profile only

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.