Understand the Spring Boot startup lifecycle and use it to locate configuration, bean-creation, context-refresh, and runner failures.
Understand the Spring Boot startup lifecycle and use it to locate configuration, bean-creation, context-refresh, and runner failures.
SpringApplication.run() bootstraps a Spring Boot application: it prepares the environment, creates and refreshes an application context, and invokes startup runners. This article explains that lifecycle at a high level. The internal constructor excerpts are a simplified Spring Boot 3.x implementation sketch, not a stable public API or a complete runnable application.
The following sections trace the public startup call into a simplified initialization sequence. Use that sequence to distinguish configuration loading, context creation, bean initialization, and startup-runner failures.
SpringApplication.run()The SpringApplication.run() method is the primary way to start a Spring Boot application. Here’s a simple example of its usage:
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class, args);
}
}JavaWhen you call SpringApplication.run(MySpringBootApplication.class, args);, several important steps take place to bootstrap your application.
SpringApplication InstanceThe first thing SpringApplication.run() does is create an instance of the SpringApplication class. This is done through one of its static run methods:
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
return new SpringApplication(primarySources).run(args);
}JavaThis line essentially calls the constructor of the SpringApplication class:
public SpringApplication(Class<?>... primarySources) {
this(null, primarySources);
}JavaThis constructor is responsible for initializing the core components needed to start the Spring Boot application.
SpringApplication InstanceThe resource-loader constructor performs the initialization shown in this simplified excerpt:
public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
this.resourceLoader = resourceLoader;
Assert.notNull(primarySources, "PrimarySources must not be null");
this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
this.webApplicationType = WebApplicationType.deduceFromClasspath();
this.bootstrapRegistryInitializers = new ArrayList<>(
getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
this.mainApplicationClass = deduceMainApplicationClass();
}JavaLet’s break down what happens here:
ResourceLoader is provided, it’s set up here. If not, the default one is used. This handles how resources (like configuration files) are loaded in your application.primarySources are the main configuration classes for your application, typically the class annotated with @SpringBootApplication.ApplicationContext that will be created.BootstrapRegistryInitializer are created. These are used during the early phase of the application’s lifecycle to customize the bootstrap process.ApplicationContext before it is refreshed.main method. This is important for logging and other contextual purposes.Once the SpringApplication instance is fully initialized, the run() method of this instance is called:
public ConfigurableApplicationContext run(String... args) {
...
}JavaHere’s what happens during this run method:
application.properties, application.yml, system properties, environment variables, and command-line arguments.ApplicationContext is created. For web applications, a WebApplicationContext is created.ApplicationContextInitializers are executed to customize the context before it is refreshed.CommandLineRunner or ApplicationRunner are executed to perform any task that needs to happen after the application is fully started.The SpringApplication.run() method is more than just a simple call to start your Spring Boot application. It orchestrates a series of well-defined steps, from setting up the environment and creating the application context, to starting the embedded server and executing custom runners.
Understanding what happens under the hood when you call SpringApplication.run() provides valuable insights into the powerful abstractions Spring Boot offers, making it easier for developers to create robust and scalable applications with minimal configuration.
Use the lifecycle to locate startup failures: configuration loading, bean creation, context refresh, or runner execution. For choosing environment-specific beans and settings, continue with Spring Boot profiles.

Senior Technical Architect at HCLTech · working with Leonteq Security AG
I have 10+ years of experience building distributed systems and fintech platforms. I write about practical, non-obvious engineering details that official documentation often skips.
Scala, JVM, AI, and backend systems. I send practical articles when there is something worth reading.
Join the newsletter