How Spring Boot Application Works Internally?
Last Updated :
04 Jan, 2025
Spring Boot Application starts using a main method, like any other Java program, and the main method is called the "run" method i.e. SpringApplication.run(),. From this run method, the application context of IOC (Inversion Of Control) searches the class annotated with @Configuration annotation which calls all the beans in the classpath and initializes those classes. Beans are stored inside a particular space in JVM (Java Virtual Machine). That particular space is known as the IOC Container.
After beans are created the requests will go to the dispatcher servlet and the dispatcher servlet will distribute all the requests among the appropriate controllers. To understand how a Spring Boot application works internally, it is essential to know its key components and the flow of the application.
Spring Boot Layered Architecture
Spring Boot follows a layered architecture in which each layer communicates with the other layer directly in a hierarchical structure.
There are 4 layers in Spring Boot as follows:
- Presentation Layer
- Business Layer
- Persistence Layer
- Database Layer

1. Presentation Layer
This layer handles all the HTTP requests made by clients, then it translates the JSON parameter to object and also authenticates the request, and transfer it to the business layer. In short, it only consists of the frontend part or we can say the view part.
2. Business Layer
This is also known as the Service layer which handles all the business logic of an application. It consists of service classes and uses services provided by the data access layers. It also performs authorization and validation.
3. Persistence Layer
It contains all the storage logic which are required and translates the business objects to database rows.
4. Database Layer
In this layer, all the CRUD (create, read update, delete) operations are performed.
Spring Boot Application Flow Architecture
Let us understand the control flow of a Spring Boot Application in the below diagram:

Explanation:
- Client makes an HTTP request(GET, POST, PUT, DELETE) to the browser.
- Then the request will go to the controller where all the requests will be mapped and handled.
- After mapping done, in Service layer all the business logic will be performed. It performs the logic on the data that is mapped to JPA(Java Persistence API) using model classes.
- In repository layer, all the CRUD operations is done for the rest APIs.
- A JSP page is returned to the user if no errors are there.
How Does Spring Boot Application Starts?
Spring Boot is very popular for It's auto-configuration feature. This means it automatically configures our application based on the dependencies added during the project creation. As we don't need to configure xml file, Spring internally do all the xml configuration which are provided by jar. We just have to use the pre-configured jars. To enable those pre-configured jars, simply we need to define starter dependencies in pom.xml file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
By adding this starter-data-jpa dependency, we get all the pre-configured JPA configuration which are needed for connecting our application with the database. Then we just need to focus on defining the JPA entities, repositories, business logic, while Spring Boot takes care of all internal configuration and database interaction.
Basic Annotations to Start a Spring Boot Application
The entry point of the Spring Boot Application is the class which contains @SpringBootApplication annotation along with the main method. The main method should contain SpringApplication.run method.
Below is the implementation of the above method:
Java
// Java program to demonstrate use of
// @SpringBootApplication Annotation
import org.springframework.boot.SpringApplication;
@SpringBootApplication
public class GFG {
public static void main (String[] args) {
SpringApplication.run(GFG.class, args);
// Data
}
}
Here we have used @SpringBootApplication annotation along with the class GFG and a main method just like other java program with SpringApplication.run method to bootstrap the application.
How @SpringBootApplication Works?
@SpringBootApplication annotation is the combination of another three annotations i.e. @Configuration, @EnableAutoConfiguration, @ComponentScan.
@SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan
@Configuration Annotation:
- This annotation configures the application context such as transaction, resource handler, view resolver, security etc.
- It is used in class level and it specifically indicates that a class declare one or more than one @Bean methods.
Below is the implementation of the above method:
Java
// Java Program to demonstrate
// use of @Configuration
// Annotation
@Configuration
public class GFG {
@Bean(name = gfg)
public demoClass demo(){
// Data
}
}
@EnableAutoConfiguration Annotation:
- This annotation will automatically configures our application we don't need to configure manually.
- It enables the auto-configuration feature of Spring Boot.
Below is the implementation of the above method:
Java
// Java Program to demonstrate
// use of @EnableAutoConfiguration
// Annotaion
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
// Annotaion used
@EnableAutoConfiguration
public class GFG {
public static void main (String[] args) {
SpringApplication("GFG.class, args");
// Data
}
}
Here we have used @EnableAutoConfiguration annotation along with the class name to perform the automatic configuration over an application.
@ComponentScan Annotation:
- This annotation will automatically scans all the beans and package declaration when the application initializes inside the class path.
- It will automatically scan all the components added to our project.
Below is the implementation of the above method:
Java
// Demonstration of use of
// @ComponentScan Annotation
@ComponentScan("com.geeksforgeeks.springboot")
@SpringBootApplication
public class GFG {
// Data
}
Here we have used @ComponentScan annotation along with the @SpringBootApplication annotation which will scan the package which is passed inside the parameter. We can also use this annotation without argument, where Spring is responsible for scan the current package and it's sub-packages. We can use these annotations separately as per our need because spring boot supports loosely coupled feature.
Spring Boot enables the developers to use a single annotation instead of using three different annotations we can use one annotation which has the default attributes of all those annotations.
Conclusion
Spring Boot is an open-source framework of java built on the top of the Core Spring framework. Here we learnt about different layers of Spring Boot architecture. We also learnt about project flow of Spring Boot application, different annotations to start the RESTful web application.
Similar Reads
Spring Boot - CommandLineRunner and ApplicationRunner Spring Boot is a powerful framework that simplifies Java application development by providing pre-configured setups. Two important interfaces in Spring Boot are CommandLineRunner and ApplicationRunner. These interfaces allow developers to run specific pieces of code once the Spring application conte
4 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read
Spring Boot - @SpringBootApplication Annotation In Spring Boot, simplifying application configuration is a key objective, and the @SpringBootApplication annotation plays a pivotal role in achieving this. Spring Boot, an extension of the Spring Framework, offers developers a rapid way to develop standalone applications. The @SpringBootApplication
4 min read
Difference Between Spring boot and Quarkus Spring Boot and Quarkus are two popular frameworks in the Java ecosystem that simplify application development. While they share some similarities, they fulfill to different needs and preferences in the software development landscape. This article explores the key differences between Spring Boot and
4 min read
What is Command Line Runner Interface in Spring Boot? Spring Boot CLI (Command Line Interface) is a command line software or tool. This tool is provided by the Spring framework for quickly developing and testing Spring Boot applications from the command prompt. In this article, we will discuss the command line runner interface in the spring boot. Sprin
3 min read
Spring Boot - Configuring a Main Class Spring Boot simplifies the process of creating and running Java applications by providing a set of conventions and auto configurations. The main class in the Spring Boot application acts as the entry point where the application starts the execution. It is responsible for bootstrapping the Spring con
4 min read
Spring Boot - Architecture Spring Boot is built on top of the core Spring framework. It simplifies and automates Spring-based application development by reducing the need for manual configuration. Spring Boot follows a layered architecture, where each layer interacts with other layers in a hierarchical order. The official Spr
3 min read
Spring Boot Ecosystem The Spring Framework is one of the most popular frameworks for developing stand-alone Java applications. Spring Boot is a part of the Spring Framework. Spring boot supports rapid application development by automating various manual configurations needed for traditional Spring MVC architecture. Sprin
4 min read
Spring Boot - Getting Started Spring Boot is a part of the larger Spring Framework ecosystem which is known for its comprehensive programming and configuration model for the modern Java-based enterprise applications. Spring Boot has emerged as a go-to framework for creating REST APIs, microservices, and web applications with les
5 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read