When you run a Spring Boot application, a lot of things happen automatically behind the scenes.
From JVM startup to bean creation, auto-configuration, and embedded server initialization, Spring Boot handles everything for you.
Spring Boot Application Startup Flow
In this blog, I’ll explain the complete startup flow of a Spring Boot application, step by step, in a way that finally made sense to me.
1. JVM Starts and Calls the main() Method
Every Spring Boot application starts like any normal Java application.
- The JVM starts
- It loads the class that contains the main() method
- The main() method is executed
example
@SpringBootApplication
public class MyAppApplication {
public static void main(String[] args) {
SpringApplication.run(MyAppApplication.class, args);
}
}
At this point, Spring Boot has not started yet.
We are still in plain Java.
2. SpringApplication.run() Is the Real Entry Point
The real Spring Boot journey begins when:
SpringApplication.run(MyAppApplication.class, args);
is called.
Internally, this method does a lot of work, but conceptually it does three important things:
- Creates a SpringApplication object
- Prepares the application environment
- Creates and refreshes the ApplicationContext
3. SpringApplication Object Is Created
Spring Boot first creates a SpringApplication object.
This object is responsible for:
- Determining whether the app is web or non-web
- Loading ApplicationContextInitializers
- Registering ApplicationListeners
- Preparing the Environment (properties, profiles)
Think of it as the bootstrapping brain of Spring Boot.
4. Environment Is Prepared
Before any beans are created, Spring Boot prepares the Environment.
This includes:
- application.properties / application.yml
- Active profiles (dev, prod, etc.)
- JVM arguments
- OS environment variables
This step is important because many configurations depend on environment values.
5. ApplicationContext Is Created
Next, Spring Boot creates the ApplicationContext, which is the core container of Spring.
Depending on the application type:
- Web app → AnnotationConfigServletWebServerApplicationContext
- Non-web app → AnnotationConfigApplicationContext
The ApplicationContext:
- Manages beans
- Handles dependency injection
- Controls the application lifecycle
6. Component Scanning Begins
Now Spring starts component scanning.
It scans packages starting from the class annotated with:
@SpringBootApplication
During scanning, Spring detects:
- @Component
- @Service
- @Repository
- @Controller
- @RestController
These classes are registered as beans inside the ApplicationContext.
7. Bean Creation and Dependency Injection
Once components are detected:
- Beans are created
- Dependencies are injected using: Constructor injection Field injection Setter injection
This is where Inversion of Control (IoC) actually happens.
Spring now manages the lifecycle of your objects.
8. Auto-Configuration in Spring Boot
This is the most powerful feature of Spring Boot.
Spring Boot checks:
- What dependencies are present on the classpath
- What properties are configured
- What conditions are satisfied
Based on this, it automatically configures beans.
Examples:
- If Spring Web is present → configure DispatcherServlet
- If JPA is present → configure EntityManager
- If Tomcat is present → configure embedded server All of this happens using conditional annotations.
9. Embedded Server Starts
For web applications:
An embedded server (Tomcat/Jetty/Netty) is started
Server is bound to the configured port (default: 8080)
DispatcherServlet is initialized
Now your application is ready to handle HTTP requests.
10. Application Is Ready🚀
At this point:
- All beans are initialized
- Auto-configuration is complete
- Server is running
Spring Boot publishes an ApplicationReadyEvent, signaling that the app has fully started.
Spring Boot Startup Flow Summary
- JVM starts and runs main() method
- SpringApplication.run() bootstraps the app
- Environment and profiles are prepared
- ApplicationContext is created
- Components are scanned and beans are created
- Auto-configuration configures required beans
- Embedded server starts
- Application becomes ready to serve requests
Why Understanding This Matters
- Understanding the startup flow helps you:
- Debug startup errors
- Answer interview questions confidently
- Customize Spring Boot behavior
- Stop treating Spring Boot as a black box This explanation helped me finally understand what Spring Boot is actually doing for us instead of just memorizing annotations.
If you’re also learning Spring Boot, I hope this clears things up for you 🙂
Top comments (0)