Free tools Windows power users keep installed
One-click scans. No signup required.
SpringApplication.run(MyApplication.class, args) coordinates an application’s startup; it is not a single command that simply starts a server. Spring Boot prepares arguments and configuration, creates and refreshes an application context, runs startup callbacks, and only then marks the application ready to accept traffic. A web server, when the application is web-enabled, is initialized during context refresh.
This walkthrough follows the Spring Boot 4.1.1 reference documentation. Treat the sequence as a lifecycle map, not a guarantee of every internal call: application type, framework version, custom listeners, and configuration can change what you observe.
As an Amazon Associate I earn from qualifying purchases.
What does SpringApplication.run() do?
The call starts a chain of lifecycle phases and returns the running ConfigurableApplicationContext if startup succeeds. In a typical Java application, the entry point is:
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
The static helper uses default Spring Boot settings. For customization, create a SpringApplication, adjust its options, and invoke its instance run method. Kotlin applications can use runApplication<MyApplication>(*args).
#1 Best Overall
A useful high-level map is:
main → bootstrap and starting event → Environment and arguments → context selection and preparation → refresh → started and live → runners → ready and accepting traffic → returned context
The map describes the main flow. Startup can branch into failure handling, and extensions or application-specific behavior can affect the events and work observed along the way.
How are bootstrap support, listeners, and arguments initialized?
Early in startup, Spring Boot establishes run support and discovers listeners. The Spring Boot 4.1.1 source listing places bootstrap-context creation, bootstrap registry initializers, headless-mode configuration, run-listener discovery, and the starting notification before Environment preparation. That is a description of this version’s listed implementation sequence, not an immutable contract for every release.
Spring Boot then creates ApplicationArguments and prepares the Environment before creating the application context. Command-line input is available in two forms:
Rank #2
ApplicationArgumentsexposes parsed options and non-option arguments to application code.- A command-line property source lets command-line values participate in configuration property resolution.
Profiles and property sources can be influenced through SpringApplication configuration. The important ordering is that this configuration work precedes context creation, so it can affect which beans and settings are used when the context is built.
How does Spring Boot choose the application context?
Spring Boot infers the application type from the classpath unless the application explicitly overrides the type or supplies a context factory. In the documented defaults, the presence of Spring MVC selects a servlet web context; when MVC is absent and WebFlux is present, Spring Boot selects a reactive web context; otherwise it uses a regular annotation-config context.
| Default context choice | Classpath condition | What it means |
|---|---|---|
| Servlet web context | Spring MVC is present | The application follows the servlet web-application path; its web server is initialized during refresh. |
| Reactive web context | MVC is absent and Spring WebFlux is present | The application follows the reactive web-application path. |
| Regular annotation-config context | Neither of the preceding web conditions selects a web context | Spring Boot creates a non-web application context. |
These are inference rules, not a prohibition on other arrangements: an application can explicitly choose its type or context factory.
The banner is printed before context creation in the listed 4.1.1 implementation. It is a visible startup detail, but it does not mark the point at which the service is initialized or ready.
What happens while the context is prepared?
The primary source is commonly the main configuration class, often annotated with @SpringBootApplication. Spring Boot also supports other source forms, including classes, packages, XML, and Groovy sources.
Rank #3
During preparation, Spring Boot attaches the Environment, applies initializers and listeners, loads bean definitions from the application’s sources, and publishes preparation events. The reference event descriptions establish two useful boundaries:
ApplicationContextInitializedEventis published after context initializers run and before bean definitions are loaded.ApplicationPreparedEventis published after bean definitions are loaded and before refresh.
Some listeners run before a context exists. Registering those listeners as ordinary beans is too late; use SpringApplication listeners or the documented automatic listener-registration mechanism when an event must be observed at that early stage. Listeners execute on the publishing thread by default, so lengthy work in one can add directly to startup time.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Why is context refresh the major startup boundary?
After preparation, Spring Boot calls the context’s refresh operation. The Spring Boot API describes refresh as refreshing the context and loading singleton beans. This is where the framework moves from definitions and setup toward creating and wiring the application’s managed objects.
For a web application, web-server initialization happens as part of this refresh phase. The event documentation places both WebServerInitializedEvent and ContextRefreshedEvent after ApplicationPreparedEvent and before ApplicationStartedEvent. The exact mechanics inside refresh belong to Spring Framework; the lifecycle point that matters here is that the web server is initialized before Spring Boot announces the started milestone.
Rank #4
When is the application live, and when is it ready?
Refresh completion and readiness are different milestones. After refresh, Spring Boot publishes ApplicationStartedEvent and changes liveness to CORRECT. It then invokes ApplicationRunner and CommandLineRunner beans. Only after those runners complete successfully does Spring Boot publish ApplicationReadyEvent and change readiness to ACCEPTING_TRAFFIC.
| Milestone | What has happened | Availability meaning |
|---|---|---|
| Context refresh completed | Spring Boot publishes ApplicationStartedEvent; startup runners have not yet completed. |
Liveness becomes CORRECT. |
| Runners completed | Spring Boot publishes ApplicationReadyEvent. |
Readiness becomes ACCEPTING_TRAFFIC. |
This distinction matters when runners perform required initialization. If the service should not receive traffic until that work has finished, keep it in a runner rather than treating context refresh or a started event as proof of readiness.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Choosing a runner
Both runner types execute after refresh and before SpringApplication.run() completes. Choose based on the argument interface your startup task needs:
ApplicationRunnerreceives the parsedApplicationArgumentsabstraction.CommandLineRunnerreceives the rawString[]arguments.
When several runners are present, use Ordered or @Order to control their order.
Which events mark the lifecycle?
The Spring Boot 4.1.1 reference lists the following application events in this order. The two context-related events shown between preparation and startup occur in that interval; they are not part of the main application-event sequence below.
| Order | Event or signal | Lifecycle point |
|---|---|---|
| 1 | ApplicationStartingEvent |
Early startup, before the Environment is prepared. |
| 2 | ApplicationEnvironmentPreparedEvent |
The Environment has been prepared. |
| 3 | ApplicationContextInitializedEvent |
Initializers have run; bean definitions have not yet loaded. |
| 4 | ApplicationPreparedEvent |
Bean definitions are loaded; refresh has not yet occurred. |
| Between 4 and 5 | WebServerInitializedEvent and ContextRefreshedEvent |
During the refresh interval, where applicable. |
| 5 | ApplicationStartedEvent |
Refresh has completed. |
| 6 | Liveness AvailabilityChangeEvent |
Liveness becomes CORRECT. |
| 7 | ApplicationReadyEvent |
Startup runners have completed successfully. |
| 8 | Readiness AvailabilityChangeEvent |
Readiness becomes ACCEPTING_TRAFFIC. |
If startup throws, Spring Boot can publish ApplicationFailedEvent instead of completing the successful path. Event timing is useful for instrumentation and integrations, but an event listener should not be used as a substitute for a runner when required work must finish before readiness.
What happens if startup fails or succeeds?
On failure
Startup exceptions may be handled by registered FailureAnalyzer implementations, which can provide a description and an action. A port already in use is one documented example of a failure that can produce an analysis. Not every exception has an analyzer. Running with --debug can display a condition-evaluation report, which helps investigate auto-configuration decisions but is not a diagnosis for every failure.
On success
Once runners finish, run returns the running ConfigurableApplicationContext. Spring Boot registers a shutdown hook by default so the context can close gracefully when the JVM shuts down.
How can you investigate slow startup?
Use startup instrumentation rather than relying on the banner or a single log line to represent the full lifecycle. Spring Boot’s ApplicationStartup and StartupStep mechanisms collect startup-step data. BufferingApplicationStartup can buffer those steps, while FlightRecorderApplicationStartup can correlate Spring lifecycle events with JVM events such as allocations, garbage collection, and class loading. Spring Boot can expose startup-step information through a startup endpoint when that endpoint is configured.
These tools provide observability, not a guaranteed speed improvement. They help locate which startup phases or operations take time; the appropriate fix depends on what the measurements show.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




