spring initializr spring-boot-starter 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 Initializr is a web-based tool specifically designed for generating Spring Boot project structure setups, making it easier for developers to create and configure projects. It provides a streamlined interface to help developers quickly bootstrap applications with essential dependencies, configurations, and default settings. Two commonly chosen dependencies when using Spring Initializr are `spring-boot-starter` and `spring-boot-starter-web`. This article aims to delve into these two starters to help developers understand their use cases, configurations, and distinctions.
Understanding Spring Starters
Spring Boot Starters are a set of convenient dependency descriptors that provide a fast and efficient way to configure commonly used dependencies. They are designed to simplify the process of integrating various Spring modules and other external libraries, reducing the amount of boilerplate setup code a developer has to write.
Spring Boot Starter
The `spring-boot-starter` dependency is a core starter, providing basic configurations needed to kickstart a Spring Boot application. Here's why it’s significant:
- Core Dependencies: It pulls in the basic dependencies required for any Spring Boot application, including:
- `spring-core`
- `spring-context`
- `spring-aop`
- `spring-beans`
- Auto-Configuration: The starter provides essential auto-configuration capabilities that Spring Boot offers, allowing for rapid application development through convention over configuration.
- No Web Layer: It does not include any web layer dependencies, making it ideal for non-web applications like batch processing tasks or standalone tools.
Below is a simple Maven and Gradle inclusion for the `spring-boot-starter`:
Maven:
- Web Server: Comes with an embedded web server (Tomcat by default, but easily switchable to Jetty or Undertow).
- Spring MVC: Includes Spring MVC capabilities, allowing you to build RESTful services with ease.
- Jackson: Facilitates JSON processing for REST API creation.
- Validation: Includes integration with the Bean Validation API (JSR-303) via Hibernate Validator.
- Non-Web Application: Use `spring-boot-starter` if your application does not interact with HTTP requests. This is common for batch processing jobs or applications not exposing RESTful endpoints.
- Web Application: Opt for `spring-boot-starter-web` for applications that will handle HTTP requests, such as RESTful APIs or MVC applications.
- Changing the default server (Tomcat) to Jetty or Undertow by excluding the default and adding the preferred server starter.
- Configuring server properties like port number, session timeout, etc., in `application.properties` or `application.yml`.
Related reading
- Spring injects dependencies in constructor without Autowired annotation
- Spring Integration Kafka Consumer Listener not Receiving messages
- Spring is losing connection to the DB and does not recover or reconnect
- Spring Java Config how do you create a prototype-scoped Bean with runtime arguments?
- Spring JPA Repository - Operator SIMPLE_PROPERTY on jsonObject requires a scalar argument
- Spring JPA selecting specific columns
- Spring Kafka- When is exactly Consumer.poll() called behind the hood?
- Spring Kafka - Consume last N messages for partitions(s) for any topic

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.