29 - Spring Boot Application Startup Process
- 23 - Spring Boot Architecture Overview
- 24 - Key Spring Boot Annotations Explained
- 25 - Auto-Configuration: How Spring Boot Does Magic
- 26 - Spring Boot Starters – The Complete Guide
- 27 - Creating a Basic Spring Boot Application (Hands-on)
- 28 - Embedded Web Servers in Spring Boot (Tomcat, Jetty, Netty)
- 29 - Spring Boot Application Startup ProcessCurrent
- 30 - Understanding the main() Method in Spring Boot
- 31 - Best Practices for Spring Boot Applications
- 32 - application.properties vs application.yml in Spring Boot
- 33 - Profiles & Environment Configuration in Spring Boot (@Profile)
- 34 - Spring Boot Logging – Complete Guide
- 35 - Spring Boot DevTools – Hot Reloading & Developer Productivity
- 36 - Using Spring Boot Actuator (Health, Metrics, Insights)
When you run a Spring Boot application, a lot happens before your application is ready to serve requests.
Understanding the startup process helps you debug failures, optimize startup time, and understand Spring Boot internals with confidence.
This post walks through the Spring Boot startup lifecycle step by step.
1. Entry Point: main() Method
Every Spring Boot application starts here:
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
This single line triggers the entire startup sequence.
2. SpringApplication Creation
SpringApplication.run() does the following:
- Creates a
SpringApplicationinstance - Determines application type (Servlet / Reactive / Non-web)
- Loads initial configuration
- Prepares environment
This sets the foundation for the startup process.
3. Environment Preparation
Spring Boot prepares the Environment, which includes:
- application.properties / application.yml
- Profile-specific configuration
- Environment variables
- Command-line arguments
Property precedence rules are applied at this stage.
4. ApplicationContext Creation
Based on application type, Spring Boot creates the appropriate context:
AnnotationConfigServletWebServerApplicationContext(Web)AnnotationConfigReactiveWebServerApplicationContext(Reactive)AnnotationConfigApplicationContext(Non-web)
This context is the IoC container.
5. Bean Definition Loading
Spring scans and registers bean definitions from:
- Component scanning
- Auto-configuration classes
- @Configuration classes
- @Bean methods
At this stage:
- Beans are defined
- Instances are not yet created (for most beans)
6. Bean Creation & Dependency Injection
Now Spring starts creating beans:
- Bean instantiation
- Dependency injection
- @PostConstruct execution
- BeanPostProcessor hooks
Singleton beans are created eagerly by default.
7. Auto-Configuration Applied
Auto-configuration classes are evaluated:
- Conditional annotations checked
- Default beans registered
- User-defined beans override defaults
This is where most of Spring Boot’s “magic” happens.
8. Embedded Web Server Startup
For web applications:
- Embedded server (Tomcat/Jetty/Netty) is created
- Server port is bound
- DispatcherServlet is registered
- Context path is applied
At this point, the server is technically running.
9. Application Events Published
Spring Boot publishes lifecycle events:
ApplicationStartingEventApplicationEnvironmentPreparedEventApplicationPreparedEventApplicationReadyEvent
You can listen to these using:
@EventListener
public void onReady(ApplicationReadyEvent event) { }
10. Application Ready State
Once everything is initialized:
- All beans are ready
- Server is accepting requests
- ApplicationReadyEvent is fired
This is the point where your application is fully up and running.
11. Common Startup Failures
Typical startup issues include:
- Port already in use
- Missing dependencies
- Bean definition conflicts
- Configuration errors
- Circular dependencies
Startup logs usually indicate the exact failure point.
12. Startup Performance Tips
- Reduce unnecessary auto-configurations
- Avoid heavy logic in constructors
- Use lazy initialization where appropriate
- Profile startup using logs and metrics
13. Summary
- Spring Boot startup is a well-defined sequence
- main() triggers SpringApplication
- Environment and context are prepared first
- Beans are registered and created
- Embedded server starts automatically
- Application becomes ready to serve requests
Understanding the startup process makes Spring Boot predictable and debuggable.
What's Next?
Next post:
30 - Understanding the main() Method in Spring Boot
We’ll zoom in on the main() method and SpringApplication.run() in detail.
