A Spring application starts by creating and initializing the Spring Container, also known as the ApplicationContext. The container is responsible for scanning classes, creating beans, injecting dependencies, loading configurations, and managing the complete lifecycle of the application. In Spring Boot, this process is automatically initiated through the SpringApplication.run() method.
Application Startup Flow
main()
|
SpringApplication.run()
|
Create ApplicationContext
|
Component Scanning
|
Bean Creation
|
Dependency Injection
|
Auto-Configuration
|
Embedded Server Startup
|
Application Ready
Step 1: Application Entry Point
Every Spring Boot application starts from the main method.
@SpringBootApplication
public class EmployeeApplication {
public static void main(String[] args) {
SpringApplication.run(
EmployeeApplication.class,
args);
}
}The run() method triggers the complete startup process.
Step 2: Create ApplicationContext
Spring creates an ApplicationContext.
It acts as the central container of the application.
Step 3: Component Scanning
Spring scans packages starting from the package containing the main class.
@Service
public class EmployeeService {
}Spring automatically detects and registers this class as a bean.
Step 4: Bean Creation
After discovering components, Spring creates bean instances.
@Service
public class EmployeeService {
}
@Repository
public class EmployeeRepository {
}Both classes become managed beans inside the container.
Step 5: Dependency Injection
Spring resolves dependencies and injects them automatically.
@Service
public class EmployeeService {
private final EmployeeRepository repository;
public EmployeeService(
EmployeeRepository repository) {
this.repository = repository;
}
}Spring creates EmployeeRepository first and injects it into EmployeeService.
Step 6: Auto-Configuration
Spring Boot automatically configures components based on project dependencies.
spring-boot-starter-data-jpa
without requiring manual setup.
Step 7: Load Configuration Properties
server.port=9090
spring.datasource.url=jdbc:mysql://localhost/testdbThese values are applied during startup.
Step 8: Start Embedded Server
For web applications, Spring Boot starts an embedded server.
spring-boot-starter-web
automatically starts Tomcat.
http://localhost:8080
Step 9: Application Ready
After all beans are initialized and the server starts, the application is ready to process requests.
1. SpringApplication.run() is called.
2. ApplicationContext is created.
3. Components are scanned.
4. Beans are instantiated.
5. Dependencies are injected.
6. Auto-configuration is applied.
7. Tomcat starts.
8. REST endpoints become available.
Benefits of the Spring Startup Process
Real-World Example
PaymentService Application
All of this happens automatically through Spring Boot's startup mechanism.
A concise interview answer is
A Spring application starts when SpringApplication.run() is executed. Spring creates the ApplicationContext, scans components, creates and injects beans, applies auto-configuration, loads configuration properties, and starts the embedded server if it is a web application. Once initialization is complete, the application is ready to handle requests.
Last updated: 11 November 2026
Previous question: What are Spring Boot starter dependencies?
Next question: What does the @SpringBootApplication annotation do internally?