Spring Boot is built on top of the Spring Framework and simplifies application development through auto-configuration, dependency management, and embedded servers. Understanding its internal workflow helps developers build and troubleshoot applications more effectively.
- Spring Boot applications start with SpringApplication.run().
- The IoC Container manages beans and dependency injection.
- Auto-configuration and component scanning reduce manual configuration.
Spring Boot Layered Architecture
Spring Boot follows a layered architecture in which each layer communicates with the other layer directly in a hierarchical structure.
- 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.
- 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.
- Persistence Layer: It contains all the storage logic which are required and translates the business objects to database rows.
- 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 Spring Boot Application Starts?
Spring Boot applications start with a main class containing the main() method and the @SpringBootApplication annotation.
- JVM executes the main() method.
- SpringApplication.run() is invoked.
- Spring creates the Application Context.
- Component scanning identifies beans and components.
- Auto-configuration configures required dependencies.
- Beans are created and stored inside the IoC Container.
- Embedded server (Tomcat, Jetty, etc.) starts.
- Application becomes ready to handle requests.
Basic Annotations to Start a Spring Boot Application
Spring Boot Application is the class which contains @SpringBootApplication annotation along with the main method. The main method should contain SpringApplication.run method.
import org.springframework.boot.SpringApplication;
@SpringBootApplication
public class GFG {
public static void main (String[] args) {
SpringApplication.run(GFG.class, args);
// Data
}
}
@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.
// 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.
// 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.
// @ComponentScan Annotation
@ComponentScan("com.geeksforgeeks.springboot")
@SpringBootApplication
public class GFG {
// Data
}
Advantages of Spring Boot Layered Architecture
- Separation of Concerns : Each layer has a specific responsibility, making the application easier to understand and maintain.
- Better Code Organization : Business logic, data access, and presentation logic are separated into different layers.
- Easy Maintenance : Changes in one layer usually do not affect other layers significantly.
- Improved Reusability: Service and repository classes can be reused across multiple controllers.
- Scalability : New features and modules can be added easily without restructuring the entire application.
- Simplified Testing : Individual layers can be tested independently using unit and integration tests.
- Loose Coupling : Dependency Injection reduces dependencies between components, improving flexibility.
