Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

Spring Boot Under the Hood, Part 1: What Happens When You Call SpringApplication.run()?

SpringApplication.run() coordinates Spring Boot startup. See how arguments, context refresh, runners, liveness, and readiness fit together.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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).

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Spring Boot then creates ApplicationArguments and prepares the Environment before creating the application context. Command-line input is available in two forms:

  • ApplicationArguments exposes 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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:

  • ApplicationContextInitializedEvent is published after context initializers run and before bean definitions are loaded.
  • ApplicationPreparedEvent is 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing a runner

Both runner types execute after refresh and before SpringApplication.run() completes. Choose based on the argument interface your startup task needs:

  • ApplicationRunner receives the parsed ApplicationArguments abstraction.
  • CommandLineRunner receives the raw String[] arguments.

When several runners are present, use Ordered or @Order to control their order.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.