Vishal's Blog
Header

29 - Spring Boot Application Startup Process

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 SpringApplication instance
  • 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:

  1. Bean instantiation
  2. Dependency injection
  3. @PostConstruct execution
  4. 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:

  • ApplicationStartingEvent
  • ApplicationEnvironmentPreparedEvent
  • ApplicationPreparedEvent
  • ApplicationReadyEvent

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.