Introduction to SpringBoot

Mastering Spring Boot: Architecture and Implementation

Learning Outcome

5

4

3

2

1

Understand overall Spring Boot architecture and layered design

Learn APIs, REST services, and Spring annotations

Understand data formats like JSON and XML

Identify roles of controller, service, and repository layers

Explain client–server communication and request response cycle

Introduction to Spring Boot Architecture

Spring Boot Architecture illustrates how Spring Boot applications function with various components.

Controller Layer

Handles requests • Calls service layer

Service Layer

Business logic • Processes data

Repository Layer

Database interaction • Uses JPA

Database

Stores and retrieves application data

Client

Sends HTTP requests (Browser, Postman)

Core Components of Spring Boot Architecture

 Auto Configuration

  • Automatically configures the application

  • No need for manual setup

Spring Boot Starter

  • Provides ready-made dependencies
  • Example: spring-boot-starter-web

Actuator

  • Used to monitor and manage application
  • Shows health, metrics, etc.

Core Components of Spring Boot Architecture

Embedded Server

Spring Data JPA

Spring Boot CLI

  • Used to run Spring Boot application using

  • Provides built-in server like: Tomcat ,Jetty

  • Used to connect and interact with database

Client

Sends request (Browser / Postman)

Controller Layer

  • Receives request
  • Calls Service layer

Service Layer

  • Processes business logic
  • Calls Repository

Interacts with database using JPA

Repository Layer

Stores or retrieves data

Database

Response Back

Response flows from Database to Repository to Service to Controller to Client.

Data Flow in Spring Boot Architecture

Data Flow in Spring Boot Architecture

Data Flow in Spring Boot Architecture

Client–Server Model in Spring Boot

  • The Client–Server Model is a communication between client and server using HTTP.
     

  • The Client (React, browser, Postman) sends a request.
     

  • The Spring Boot Server receives the request and processes it

The request is handled by:

  • Controller → receives request

  • Service → processes logic

  • Repository → interacts with database
     

The Server sends response back to the client in JSON format.

Request–Response Lifecycle

1

2

3

4

5

6

Client sends request

DispatcherServlet receives it

HandlerMapping finds the controller

Controller processes request

Service layer runs business logic

Repository gets data from DB

7

Response returned to client

Role of Embedded Servers

Common embedded servers:

Tomcat

Jetty

Undertow

Spring Boot includes embedded web servers that allow applications to run without external server setup.

These servers automatically start when the application runs.

Controller Layer and Request Handling

In Spring Boot architecture, the Controller Layer is responsible for handling incoming HTTP requests from the client and sending back appropriate responses.

It acts as a bridge between the client (browser, mobile app, API consumer) and the backend business logic (Service Layer).

Important Controller Annotations

@RestController

Used to mark a class as a REST API controller.

@GetMapping

Handles HTTP GET requests.

@PostMapping

Handles HTTP POST requests.

Service Layer and Business Logic

The Service Layer in a Spring Boot application is responsible for implementing the core business logic of the system.

It acts as an intermediate layer between the Controller Layer and the Repository (Data Access) Layer.

In Spring Boot, the service layer is typically marked using the @Service annotation.

Purpose of @Service:

  • Indicates that the class contains business logic.

  • Enables dependency injection in controllers.

The Repository Layer in a Spring Boot application is responsible for handling all database-related operations.

It acts as an intermediate layer between the Service Layer and the database, allowing the application to interact with the data source in a structured way.

In Spring Boot, the repository layer commonly uses Spring Data JPA, which simplifies database interaction.

Spring Data JPA provides ready-made methods for common database operations such as: save(),findById(),findAll(),deleteById()

Repository Layer and Database Interaction

Web applications exchange data between client and server using structured formats.

The most common formats are JSON and XML.

Data Exchange Formats in Web Applications

Why JSON and XML Are Used ?

These formats allow systems built with different technologies to communicate with each other efficiently.

Benefits:

  • Structured data representation

  • Platform independent communication

  • Easy data transfer over HTTP

JSON Format: Structure and Advantages

JSON (JavaScript Object Notation) is a lightweight data format used widely in modern web applications.

Example:

{
"id": 101,
"name": "John",
"course": "Spring Boot"
}

Advantages:

Lightweight and faster
 

Easy to read and write
 

Easily parsed by most programming languages
 

Widely used in REST APIs

XML Format: Structure and Advantages

XML (Extensible Markup Language) is another format used for structured data exchange.XML represents data using tags, making it structured and easy to read.

<student>
<id>101</id>
<name>John</name>
<course>Spring Boot</course>
</student>

Example:

Advantages:

Structured and organized data format
 

Platform independent data exchange
 

Human readable and easy to understand
 

Self-descriptive using custom tags

JSON        XML: Comparison

Features

JSON

XML

Structure

Lightweight

Verbose

Speed

Faster
Slower

Readability

Easy

More complex

Usage

REST APIs

SOAP Services

Spring Boot handles content negotiation automatically using:

HTTP Headers – The client specifies the required format (e.g., application/json or application/xml).

Message Converters – Spring Boot uses built-in message converters to convert Java objects into the requested format like JSON or XML.

Content Negotiation in Spring Boot

Content Negotiation is a mechanism that allows the server to return responses in different data formats, such as JSON or XML, based on what the client requests.

What is an API ?

An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate and exchange data with each other.

API defines

Available Endpoints
The specific URLs where requests can be sent to access resources or services.

Request Methods
The type of operation to perform, such as GET, POST, PUT, or DELETE.

What are Web Services ?

Web services enable communication between applications over the internet using standardized protocols.

They allow systems developed in different languages to interact with each other.

Types of Web Services

REST (Representational State Transfer)

Uses HTTP methods and commonly returns JSON data.

SOAP (Simple Object Access Protocol)

Uses XML messaging format and strict standards.

REST       SOAP

Feature

REST

SOAP

Data format

JSON / XML

XML

Protocol

HTTP

HTTP/SMPT

Speed

Faster

Slower

Flexibility

High

Strict

High-Level Implementation of REST API

Concepts Needed to Create REST API

🌐 HTTP Methods

Used to retrieve, create, update, and delete data.

🔗 URL Endpoints

Specific URLs used to access resources in the API.

📄 JSON Data Format

Used to send and receive data between client and server.

🎮 Controller Classes

Handle incoming API requests and return responses.

⚙️ Service Layer

Contains the business logic and processes the data.

🗄️ Database Integration

Stores and retrieves application data from the database.

Understanding Annotations in Spring Boot

Annotations are special markers in Java that provide metadata to the Spring framework. They help configure the application automatically without writing complex configuration files.

Annotations simplify development by:

Commonly Used Spring Boot Annotations

Main class annotation

Creates REST APIs

Maps HTTP requests

Marks service classes

Handles database operations

Injects dependencies

@SpringBootApplication

@RestController

@RequestMapping

@Service

@Repository

@Autowired

Inversion of Control (IoC) Concept

Inversion of Control is a design principle where the control of object creation and dependency management is transferred from the programmer to the Spring framework.

Benefits of IOC:

Better scalability

Easier maintenance

Loose coupling

Dependency Injection (DI) Implementation

Dependency Injection (DI) is a design technique where the objects that a class needs (dependencies) are provided from outside instead of being created inside the class.

This helps in reducing tight coupling between classes and makes the application easier to maintain and test.

In Spring Boot, dependency injection is mainly performed using annotations such as 

@Autowired

@Autowired
private StudentService service;

Example

Summary

5

4

3

2

1

Learn APIs, REST services, and Spring annotations

Understand data formats like JSON and XML

Identify roles of controller, service, and repository layers

Explain client–server communication and request response cycle

Understand overall Spring Boot architecture and layered design

Quiz

Which component in Spring MVC acts as the Front Controller?

A.  Service

B.  Repository

C. DispatcherServlet

D.  ViewResolver

Which component in Spring MVC acts as the Front Controller?

A.  Service

B.  Repository

C. DispatcherServlet

D.  ViewResolver

Quiz-Answer

SpringBoot - Mastering Spring Boot: Architecture and Implementation

By Content ITV

SpringBoot - Mastering Spring Boot: Architecture and Implementation

  • 55