Understanding how a Spring Boot application starts is essential for diagnosing startup failures, configuration issues, bean instantiation problems, and production-grade deployments.
This guide explains the complete Spring Boot startup process — from JVM launch to the application being ready to serve requests — in a step-by-step and production-aware way.
This article is ideal for:
- Beginners learning Spring Boot
- Developers debugging startup issues
- Engineers building scalable services
What Is the Startup Flow in Spring Boot?
When you run a Spring Boot application, there is much more happening than just starting the JVM and launching your main class. Spring Boot initializes:
- Environment
- Configuration
- Beans
- Auto-configuration
- Embedded server
- Application context
Each of these steps plays a role in how the application behaves at runtime.
Step 1: JVM Starts and main() Is Invoked
Every Spring Boot application starts like a normal Java app:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
The JVM loads your class and calls main(). Nothing Spring-specific happens before this point.
Step 2: SpringApplication.run() Begins the Framework
When SpringApplication.run() is called:
- Spring Boot determines application type (web or non-web)
- Prepares the environment
- Loads application arguments
- Creates an instance of
SpringApplication
This method triggers the real Spring Boot machinery.
Step 3: Environment and Property Resolution
Spring Boot prepares the environment:
- Reads
application.properties/application.yml - Applies active profiles
- Loads environment variables
- Applies command line arguments
At this stage, no beans are created yet.
Step 4: Create ApplicationContext
Spring Boot creates an ApplicationContext:
- For web apps:
AnnotationConfigServletWebServerApplicationContext - For reactive apps:
ReactiveWebServerApplicationContext - For CLI apps:
GenericApplicationContext
This context will hold all bean definitions and manage lifecycle.
Step 5: Bean Definitions Are Registered
Spring Boot scans for beans using:
@ComponentScan- Auto-configuration
- Explicit configuration classes
Beans annotated with:
@Component@Service@Repository@Controller@Configuration
are registered at this stage.
If a class is not in the scanned package, it will not be detected automatically.
Learn more about bean discovery and lifecycle here:
https://springbootfixes.com/how-spring-boot-creates-beans-bean-lifecycle-simplified-for-production/
Step 6: Auto-Configuration Happens
Spring Boot uses auto-configuration to set up beans based on the classpath, existing beans, and property settings.
Examples:
- DataSource for JDBC
- Embedded servlet container (Tomcat/Jetty)
- Jackson for JSON serialization
- Error handling defaults
Auto-configuration ensures your app works with sensible defaults without manual setup.
Step 7: Bean Instantiation and Dependency Injection
Spring now:
- Instantiates beans
- Injects dependencies
- Resolves constructors
- Applies scopes and proxies
This is where:
BeanCreationExceptioncan occur- Circular dependencies show up
- Missing beans get flagged
Most startup issues originate in this phase.
Step 8: BeanPostProcessors and Initialization Callbacks
Spring applies BeanPostProcessors to modify beans before and after initialization.
Common callbacks include:
@PostConstructInitializingBean- Custom init methods
This is also where AOP proxies are created (for transactions, caching, security, etc.).
Step 9: Embedded Web Server Starts
For web applications:
- Tomcat, Jetty, or Undertow starts
- Server binds to configured port
- DispatcherServlet is registered
If the port is already in use (e.g., 8080), you’ll get a startup failure.
Learn how to fix this here:
https://springbootfixes.com/how-to-fix-port-8080-already-in-use-error-in-spring-boot/
Step 10: ApplicationReadyEvent Is Published
After everything is initialized, Spring Boot publishes:
ApplicationStartedEventApplicationReadyEvent
You can hook into these to run logic after startup:
@EventListener(ApplicationReadyEvent.class)
public void onReady() {
// application has started
}
How Configuration Affects Startup
Profile and configuration files influence startup behavior:
application.propertiesvsapplication.yml- Active profiles (
dev,test,prod) - Environment variable overrides
Configuration is resolved before bean creation, so it directly impacts how the application initializes.
See how profiles interact with configuration:
https://springbootfixes.com/spring-boot-configuration-and-profiles-explained-beginner-to-production-guide/
Production Startup Errors & What They Mean
Port Already in Use
Occurs when the embedded server cannot bind to a port. Diagnose via logs.
BeanCreationException
Comes from misconfigured beans, missing dependencies, circular references.
Profile Misconfiguration
Wrong active profile → wrong configuration files loaded.
These issues are easier to debug if you understand the startup flow.
Startup Flow Summary
- JVM starts
- SpringApplication.run() invoked
- Environment prepared
- ApplicationContext created
- Beans registered and instantiated
- Auto-configuration applied
- Embedded server started
- ApplicationReadyEvent published
This mental model helps you debug startup issues efficiently.
Related Spring Boot Articles
Understanding application startup complements other core concepts:
- Spring Boot Hello World Example
https://springbootfixes.com/spring-boot-hello-world-example-beginner-friendly/ - Spring Boot Project Structure Explained
https://springbootfixes.com/spring-boot-project-structure-explanation/ - Spring Boot Configuration and Profiles
https://springbootfixes.com/spring-boot-configuration-and-profiles-explained-beginner-to-production-guide/
Final Verdict
This guide ties together the configuration, bean lifecycle, startup mechanics, and web server initialization — all crucial for diagnosing real startup problems in Spring Boot.
You can safely submit this page for indexing now, as it:
Is linked internally to key posts in your site
Matches user search intent clearly
Contains practical, real-world explanations
