On This Page
The odd part is the order. The log says the app started. Three lines later it says the app failed, and then it shuts itself down.
INFO o.e.recon.ReconApplication : Started ReconApplication in 3.104 seconds (process running for 3.6)
ERROR o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:...)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:...)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:...)
at org.example.recon.ReconApplication.main(ReconApplication.java:12)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.example.recon.NightlyReconRunner.run(NightlyReconRunner.java:21)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:...)
... 3 more
INFO com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
That's the shape a nightly reconciliation job prints on Spring Boot 2.7 through 4.x when its CommandLineRunner throws. I couldn't pull Spring jars into this session (no access to Maven Central from the workspace), so the Spring lines above are assembled from the message strings in SpringApplication at the v2.7.18 tag and on main, with line numbers left as .... The Caused by line is real JDK 21 output from my lab. Logger names are shortened; the timestamp, PID and thread columns are trimmed.
People search for this as "APPLICATION FAILED TO RUN", because it feels like the sibling of the famous banner. Spring Boot never prints that banner. What it prints is the log line Application run failed, and the important thing about that line is what's missing around it: there's no starred APPLICATION FAILED TO START block, no Description, no Action. Boot is telling you it had nothing smart to say, so here's the raw trace.
Started or not started? That decides everything
Before you read a single frame, look at what came right before Application run failed. Two minutes, two cases.
Started ... in N seconds is in the log. The application context refreshed fine, the web server (if any) came up, and then something in the post-start phase blew up. In practice that's a CommandLineRunner or ApplicationRunner. The top exception will be IllegalStateException: Failed to execute CommandLineRunner (or ApplicationRunner), and the cause underneath is your code.
There's no Started line. The failure happened while the context was refreshing: a bean's constructor, an @PostConstruct, a @Bean method, a property that wouldn't convert. Boot ran its failure analyzers over the exception, none of them recognised it, and it fell back to the plain log line. You'll usually see BeanCreationException or UnsatisfiedDependencyException near the top. Read it bottom-up, the way the stack trace article walks through.
If you instead got the starred banner, you're in a different article: APPLICATION FAILED TO START explained. Boot recognised the failure there and wrote you a Description.
Two commands that settle it from a log file or a container:
grep -nE "Started .* in [0-9.]+ seconds|Application run failed|APPLICATION FAILED TO START" app.log
grep -nA3 "Failed to execute (CommandLineRunner|ApplicationRunner)" app.log
In Kubernetes, run the first one against kubectl logs deploy/recon --previous, because the container that failed is not the one that's restarting right now.
My own first guess on a job like this was wrong, and for a dull reason. I saw Started ReconApplication in the CI summary, saw exit code 1, and went hunting for a shutdown hook problem. The hook was fine. The summary truncated the log after the first ERROR line, so I never saw Failed to execute CommandLineRunner until I pulled the full artifact.
Get the same error in five minutes
You need any Spring Boot 3.x or 4.x project with no web starter (2.7 behaves the same), a JDK 17 or newer, and Maven or Gradle. I used a payment reconciliation job as the example: it takes a business date as its first program argument and pulls settlements for that day. Nothing here touches a real database, so it's safe anywhere.
The application class is the generated one:
@SpringBootApplication
public class ReconApplication {
public static void main(String[] args) {
SpringApplication.run(ReconApplication.class, args);
}
}
The runner is where the trouble lives:
@Component
class NightlyReconRunner implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(NightlyReconRunner.class);
@Override
public void run(String... args) {
LocalDate businessDate = LocalDate.parse(args[0]); // no argument passed: ArrayIndexOutOfBoundsException
log.info("Reconciling settlements for {}", businessDate);
}
}
Steps:
Step 1 - package it
$ ./mvnw -q package -DskipTests
Expected: target/recon-0.0.1-SNAPSHOT.jar exists.
Step 2 - run it with no business date
$ java -jar target/recon-0.0.1-SNAPSHOT.jar; echo "exit=$?"
Expected: "Started ReconApplication in ...", then "Application run failed",
then IllegalStateException: Failed to execute CommandLineRunner
with Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0,
and exit=1.
Step 3 - run it with a bad date
$ java -jar target/recon-0.0.1-SNAPSHOT.jar 2026-13-01; echo "exit=$?"
Expected: same wrapper, now caused by
java.time.format.DateTimeParseException: Text '2026-13-01' could not be parsed:
Invalid value for MonthOfYear (valid values 1 - 12): 13
The two Caused by messages are copied from my JDK 21.0.13 run of the same two calls outside Spring. The wrapper text is from the source, as noted above.
For the second flavour, the one with no Started line, delete the runner and add a bean that fails during refresh with an exception no failure analyzer knows:
@Component
class FxRateCache {
@PostConstruct
void warmUp() {
throw new IllegalStateException("FX rate feed returned 0 rows for EUR/USD"); // fails during refresh
}
}
Now the log has no Started line. You get Application run failed, then BeanCreationException: Error creating bean with name 'fxRateCache': Invocation of init method failed, then your message at the bottom.
How you know you hit this and not its neighbours: the exact text Application run failed, and no starred banner anywhere above it. If you see the banner, a failure analyzer claimed the exception. If the process printed nothing at all and exited, check that a web starter or a non-daemon thread was supposed to keep it alive; that's a different problem (the app starts then shuts down cleanly with exit 0).
Teardown is rm -rf on the project. Nothing else was touched.
Start here if you're in a hurry
Application run failed means SpringApplication.run() caught an exception, closed the context, and found no failure analyzer that could explain it. If Started appears above it, a runner threw. If not, a bean failed during refresh. Either way the useful line is the last Caused by, and it's almost always your own code or your own configuration.
Where 'Application run failed' comes from in SpringApplication
I read SpringApplication at the v2.7.18 tag and on main (the 4.x line) to stop guessing. The structure is the same in both, and it explains every odd thing about this error.
run() puts almost everything inside one try block: refreshing the context, logging the Started line, publishing the started event, and calling the runners. Roughly, in order:
run()
|- create and refresh ApplicationContext (beans, @PostConstruct, web server)
|- afterRefresh
|- log "Started X in N seconds" <- printed BEFORE runners
|- listeners.started(...)
|- callRunners(...) <- your CommandLineRunner / ApplicationRunner
'- catch (Throwable ex) -> handleRunFailure(context, ex, listeners)
So Started doesn't mean "finished". It means "the context is up and the runners are about to go". That surprised me more than anything else here. I'd always read that line as the finish line.
callRunner wraps whatever your runner throws in IllegalStateException with the message Failed to execute plus the interface's short name, CommandLineRunner or ApplicationRunner. That's why the top exception names the interface and never your class. Your class shows up one level down.
handleRunFailure then does four things. It works out an exit code, tells the run listeners the run failed (that's where ApplicationFailedEvent comes from), reports the failure, and closes the context in a finally block. The close is why you see Hikari's Shutdown initiated... and other teardown logging after the error. It's cleanup, not a second failure.
Reporting is the part that decides banner or no banner. Boot asks each SpringBootExceptionReporter it loaded from spring.factories to report the exception. The standard one is FailureAnalyzers, which walks the cause chain looking for something one of its analyzers recognises: a port in use, a missing bean, a failed property binding, a missing DataSource URL. If one matches, you get the starred APPLICATION FAILED TO START block from LoggingFailureAnalysisReporter. If none match, reportFailure logs Application run failed at ERROR with the full exception. An ArrayIndexOutOfBoundsException in your runner, or your own IllegalStateException in @PostConstruct, means nothing to any analyzer, so you get the plain line.
Last detail: the exception is marked as already logged before run() rethrows it. That's why you don't see the same trace twice when it escapes main. Boot's handler swallows the duplicate on the main thread.
The fix, and what it costs
The fix is whatever the last Caused by says. That sounds glib, but it's the honest answer: by the time you see this line, Spring has already done its part correctly. What changes is where you look.
A runner threw. Open the class named in the first frame under Caused by. In the lab it was the missing argument. The fix is to validate input before the work starts and fail with a message a human can act on:
@Override
public void run(String... args) {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: recon.jar <business-date yyyy-MM-dd>, got " + args.length + " arguments");
}
LocalDate businessDate = LocalDate.parse(args[0]);
reconService.reconcile(businessDate);
}
Same exit code, much better log line. If the job is launched by a scheduler that passes the date as --recon.business-date=2026-12-05 instead, switch to ApplicationRunner and read args.getOptionValues("recon.business-date"), or bind it to a @ConfigurationProperties record and validate it at startup.
Watch the argument placement while you're there. java -jar app.jar 2026-12-05 passes the date to your runner. java 2026-12-05 -jar app.jar hands it to the launcher, which tries to load a main class called 2026-12-05 and fails before Spring ever runs. And in a container, an ENTRYPOINT ["java","-jar","app.jar"] plus args: in the pod spec is how the date reaches main.
A bean failed during refresh. Treat it like any BeanCreationException: find the bean in the deepest Error creating bean with name, then the real cause under it. The BeanCreationException article covers that path in detail.
Things that aren't fixes. Wrapping the runner body in try { ... } catch (Exception e) { log.error(...) } makes the error disappear and the exit code turn into 0. Your scheduler will mark a reconciliation that never ran as a success. I've seen exactly that, and the first person to notice was finance, two days later. Turning on debug=true won't help either; the condition report explains missing beans, not a runner that threw. And spring.main.lazy-initialization=true doesn't fix a refresh failure, it moves it to the first request.
Exit codes. By default the exception escapes main and the JVM exits with 1, which is what most schedulers need. If the job needs distinct codes (2 for bad input, 3 for an upstream outage), make your exception implement ExitCodeGenerator, or register an ExitCodeExceptionMapper bean. Boot checks the mapper only while the context is still active, and checks the cause chain for an ExitCodeGenerator otherwise. That's a topic of its own; the short version is that you never get a meaningful code by swallowing the exception.
One caveat I'd check if your exit code looks wrong: a Spring Boot issue reported that with spring-boot-devtools on the classpath, a failing command-line app on 2.5.x exited with 0 instead of 1. DevTools has no business in a packaged batch job anyway. Keep it as optional (Maven) or developmentOnly (Gradle) so it never reaches the jar you deploy.
How I'd write a runner that fails well
Keep the runner thin. It should parse and validate its input, call one service method, and nothing else. All the actual reconciliation logic sits in a normal @Service that you can test without starting a context.
@ConfigurationProperties("recon")
@Validated
record ReconProperties(@NotNull LocalDate businessDate) {}
@Component
class NightlyReconRunner implements ApplicationRunner {
private final ReconProperties props;
private final ReconService reconService;
NightlyReconRunner(ReconProperties props, ReconService reconService) {
this.props = props;
this.reconService = reconService;
}
@Override
public void run(ApplicationArguments args) {
reconService.reconcile(props.businessDate());
}
}
With @ConfigurationPropertiesScan on the application class and spring-boot-starter-validation on the classpath, a missing --recon.business-date now fails during refresh. And here's the nice part: a binding validation failure is something Boot's analyzers do recognise, so instead of Application run failed you get the starred banner with a Description that names the property. Moving validation from the runner into configuration turned an anonymous stack trace into a sentence.
Two more habits. Give runners an @Order if there's more than one, because the first one to throw stops the rest and you want that order to be deliberate. And don't do long-running work in a runner of a web app: the web server is already accepting traffic while it runs, and readiness only flips to accepting traffic after the runners finish.
The test that would have caught this
For a job app, the cheapest test is the one that starts the real context with no arguments and expects it to fail with a clear message:
@Test
void failsFastWithoutBusinessDate() {
assertThatThrownBy(() -> SpringApplication.run(ReconApplication.class))
.hasRootCauseInstanceOf(BindValidationException.class);
}
Pair it with one that passes --recon.business-date=2026-12-05 against a stubbed ReconService and asserts the context runs to completion. In CI, run the packaged jar once with a known-good date and check $?. That last check is the one that catches a swallowed exception, because only the exit code tells the truth.
In production, alert on the exit code of the job and on the literal string Application run failed in your log pipeline. Both are stable across versions.
Version notes. I checked the strings at v2.7.18 and on main: Application run failed and Failed to execute CommandLineRunner / Failed to execute ApplicationRunner are unchanged across that range, and so is the order of Started before the runners. On current versions (I checked main), a native image prints the failure line to standard output instead of through the logger, so grep stdout too if you build native. What changes between versions is which failures analyzers recognise, so the same bug can produce the banner on one version and this plain line on another.
If you remember nothing else
Application run failedwith no starred banner means no failure analyzer understood the exception. The answer is in the lastCaused by.Started ... in N secondsis logged before your runners run. Seeing it above the error points straight at aCommandLineRunnerorApplicationRunner.- The top exception names the interface (
Failed to execute CommandLineRunner), not your class. Look one level down. - Never catch-and-log inside a runner to make this go away. The exit code is your scheduler's only signal.
- Validate job input as
@ConfigurationPropertiesand the failure turns into a readable banner instead.
The searches that land people here
What does "Application run failed" mean in Spring Boot?
SpringApplication.run() caught an exception, closed the application context and found no failure analyzer that could explain it, so it logged the raw exception at ERROR. Read the last Caused by in the trace; that's the actual fault. The message is the same from Boot 2.7 through 4.x.
Why does Spring Boot fail after "Started Application in X seconds"?
Because the Started line is logged before CommandLineRunner and ApplicationRunner beans run. A runner that throws gets wrapped in IllegalStateException: Failed to execute CommandLineRunner, and the context is shut down. Fix the runner, not the startup.
Is "APPLICATION FAILED TO RUN" a real Spring Boot error?
No. Boot's banner is APPLICATION FAILED TO START, printed when a failure analyzer recognises the cause. When none does, Boot logs Application run failed instead. If you have the banner, see APPLICATION FAILED TO START explained.
How do I make a Spring Boot command-line app return a non-zero exit code?
Let the exception escape run(); the JVM then exits with 1. For specific codes, have the exception implement ExitCodeGenerator or register an ExitCodeExceptionMapper bean. Catching and logging the exception inside the runner gives you exit code 0, which hides the failure.