In a Spring Boot application, these three dependencies each play a distinct role in building a typical data-driven web application:
Function: Data access layer (database interaction)
Provides an abstraction over JPA (Java Persistence API).
Lets you interact with databases using Java objects (entities) instead of writing raw SQL.
Automatically implements common CRUD operations (Create, Read, Update, Delete).
Supports query generation from method names (e.g., findByName()).
Example role:
You define an Entity class → Spring Data JPA maps it to a table.
You create a Repository interface → Spring auto-generates the implementation.
Function: Database (data storage)
A lightweight, in-memory database often used for development and testing.
Starts automatically when your app runs and resets when it stops.
No installation needed; embedded inside your app.
Example role:
Stores your application data temporarily.
Useful for quick prototyping without setting up MySQL/PostgreSQL.
Function: Web layer (handling HTTP requests)
Enables building REST APIs and web applications.
Uses Spring MVC under the hood.
Handles HTTP requests (GET, POST, etc.) and sends responses (usually JSON).
Example role:
Define a @RestController → handles incoming API requests.
Maps URLs to methods using annotations like @GetMapping.
Think of a simple flow:
A client (browser/app) sends an HTTP request → handled by Spring Web
The controller calls a service/repository → uses Spring Data JPA
Data is fetched/stored in → H2 Database
Response is returned to the client as JSON
Spring Web → Waiter (takes your order)
Spring Data JPA → Chef (prepares the data logic)
H2 Database → Kitchen storage (holds ingredients/data)