On This Page
Read a Spring Boot stack trace from the bottom. The top line tells you who gave up. The last Caused by tells you what broke.
That's most of this article in two sentences. The rest is why it holds, the two cases where it doesn't (one of them is Boot hiding the trace from you on purpose), and how to get from that last line to the bean, property or host you need to change.
The trace in front of you
Here's the shape a Spring Boot 3.x or 4.x app prints when a bean's @PostConstruct tries to load FX rates from a database that isn't there. I couldn't pull Spring jars into this session's workspace, so this block is assembled from the message strings in the Spring Framework, HikariCP and PgJDBC sources, with frames trimmed to .... Treat it as the shape, not a paste:
ERROR o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rateController' ...: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'rateCache': Invocation of init method failed
at org.springframework.beans.factory.support.ConstructorResolver...
... (about 20 framework frames)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rateCache': Invocation of init method failed
...
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
...
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Connection to fx-db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
...
Caused by: org.postgresql.util.PSQLException: Connection to fx-db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
...
Caused by: java.net.ConnectException: Connection refused
... 52 more
Five Caused by lines. In a real log the whole thing runs past 150 lines, because every layer drags its own frames along: CGLIB, reflection, the bean factory recursing into itself.
The top line is the one people paste into Google. It names rateController, a class that did nothing wrong. It only needed rateCache, which needed a connection, which needed a TCP socket to fx-db:5432, which got refused. The fix lives at the bottom. Always the bottom, at least for the first look.
Which of these lines is Spring talking?
Before reading anything, sort the lines into two piles: wrappers and carriers.
A wrapper is an exception thrown by code that caught something it couldn't handle and rethrew it with context. A carrier is the exception that actually describes the fault. In a Spring Boot startup trace, these are nearly always wrappers:
| Exception | Who throws it | What it adds |
|---|---|---|
UnsatisfiedDependencyException |
the bean factory, while injecting | which bean and which injection point wanted the broken one |
BeanCreationException |
the bean factory | which bean failed, and the phase ("Invocation of init method failed") |
BeanInstantiationException |
the bean factory | the constructor or factory method that threw |
ApplicationContextException |
the context, usually around the web server | "Unable to start web server" |
IllegalStateException: Failed to load ApplicationContext |
Spring's test framework | nothing, other than "this was a test" |
CannotGetJdbcConnectionException |
Spring JDBC | that it was a JDBC connection request |
And these tend to be carriers: anything from java.net, javax.net.ssl, a JDBC driver (PSQLException, SQLException subclasses), a YAML parser, the JVM's class loading errors, and Spring's own exceptions that sit at the bottom, like NoSuchBeanDefinitionException or a property BindException.
A bean, if you need it: an object Spring creates and wires for you. A bean factory is the part of the container that creates them. When bean A needs B and B fails, the factory catches B's failure and throws a fresh exception about A with B's failure as its cause. That's where the nesting comes from. Every hop in your dependency graph can add one Caused by.
Then do the two-minute triage:
grep -n '^Caused by:' app.log | tail -1 # the deepest cause, with its line number
grep -n -m1 -E 'Application run failed|APPLICATION FAILED TO START' app.log # which reporting path Boot took
kubectl logs deploy/fx-rates --previous | grep 'Caused by:' | tail -1 # the run that died, not the one restarting
None of these need Actuator or a running app. They work on whatever log you have.
My own first instinct, the first time I sat down to do this properly, was to read the top line and search for "UnsatisfiedDependencyException rateController". It felt sensible: that's the error, it's in red, it's the first thing printed. It sent me into constructor injection and component scanning for a good while. Nothing was wrong with either.
Make it nest on purpose
You don't need Spring to see how the chain is built. The JDK prints Caused by and ... N more, and Spring's wrappers are ordinary exceptions with a cause. So here's a lab you can run anywhere, with the same shape as the startup failure above, one hop shorter.
What you need: any JDK 17+. I ran it on OpenJDK 21.0.13. No build tool.
The code. Save as ChainLab.java:
import java.net.ConnectException;
public class ChainLab {
static class WrapperException extends RuntimeException {
WrapperException(String msg, Throwable cause) { super(msg, cause); }
}
static void openSocket() throws ConnectException {
throw new ConnectException("Connection refused"); // the carrier: the only real fault
}
static void driverConnect() {
try { openSocket(); }
catch (ConnectException e) { throw new WrapperException("Connection to fx-db:5432 refused", e); }
}
static void poolStart() {
try { driverConnect(); }
catch (RuntimeException e) { throw new WrapperException("Failed to initialize pool", e); }
}
static void createBean(String name) {
try { poolStart(); }
catch (RuntimeException e) { throw new WrapperException("Error creating bean with name '" + name + "'", e); }
}
static void refresh() {
try { createBean("rateRepository"); }
catch (RuntimeException e) { throw new WrapperException("Error creating bean with name 'rateController'", e); }
}
public static void main(String[] args) {
try { refresh(); }
catch (RuntimeException e) {
e.printStackTrace();
Throwable root = e;
int depth = 0;
while (root.getCause() != null && root.getCause() != root) { root = root.getCause(); depth++; }
System.err.println();
System.err.println("depth=" + depth + " root=" + root);
System.err.println("thrown at " + root.getStackTrace()[0]);
}
}
}
Steps:
Step 1 — compile
$ javac ChainLab.java
Expected: no output.
Step 2 — run it and keep the output
$ java ChainLab 2>&1 | tee run.log
Expected: a trace with four Caused by lines, then the depth and root.
What I got, verbatim:
ChainLab$WrapperException: Error creating bean with name 'rateController'
at ChainLab.refresh(ChainLab.java:25)
at ChainLab.main(ChainLab.java:29)
Caused by: ChainLab$WrapperException: Error creating bean with name 'rateRepository'
at ChainLab.createBean(ChainLab.java:21)
at ChainLab.refresh(ChainLab.java:24)
... 1 more
Caused by: ChainLab$WrapperException: Failed to initialize pool
at ChainLab.poolStart(ChainLab.java:17)
at ChainLab.createBean(ChainLab.java:20)
... 2 more
Caused by: ChainLab$WrapperException: Connection to fx-db:5432 refused
at ChainLab.driverConnect(ChainLab.java:13)
at ChainLab.poolStart(ChainLab.java:16)
... 3 more
Caused by: java.net.ConnectException: Connection refused
at ChainLab.openSocket(ChainLab.java:9)
at ChainLab.driverConnect(ChainLab.java:12)
... 4 more
depth=4 root=java.net.ConnectException: Connection refused
thrown at ChainLab.openSocket(ChainLab.java:9)
Confirmation signal: the last Caused by and the root= line name the same exception. And grep '^Caused by:' run.log | tail -1 on the saved file printed Caused by: java.net.ConnectException: Connection refused, which is the line you'd want from a 150-line Spring log too.
Look at ... 4 more on the last block. It doesn't mean four frames were lost. It means the next four frames are identical to the bottom four frames of the exception printed above it, so the JDK skips them. In a Spring trace that's how 50 lines of bean-factory recursion collapse to ... 52 more. Nothing's hidden that you need.
Teardown: delete ChainLab.java, ChainLab*.class and run.log. Nothing else was touched.
The one-paragraph version
Spring builds your app as a graph of beans, and every place one bean waits on another is a place where a failure gets caught and rethrown with a new message. So a single refused socket becomes five exceptions, each one describing the same fault from one layer further away. The top describes it from the furthest away. Read the last Caused by first, then walk upward only far enough to learn which bean and which setting led there.
Why Spring wraps everything twice
There are actually two reporting paths at startup, and which one you get changes what's in your log. This was the part that surprised me when I read SpringApplication instead of guessing.
When SpringApplication.run fails, it calls reportFailure, which first offers the exception to every registered exception reporter. The main one runs Boot's failure analyzers: small classes that recognise specific exceptions somewhere in the chain (a missing bean, a port in use, a binding failure) and turn them into a Description and Action. If an analyzer matches, Boot prints the APPLICATION FAILED TO START banner and returns. If none matches, it logs Application run failed at ERROR with the full exception. You can see both branches in SpringApplication.java at the 3.5.0 tag.
Here's the catch. In LoggingFailureAnalysisReporter, the banner goes out at ERROR, but the stack trace it analysed goes out at DEBUG. So when an analyzer matches, there is no stack trace in your log by default. Only the banner, plus one WARN line from AbstractApplicationContext.refresh:
WARN ... Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ...
That WARN concatenates the exception into the message string instead of passing it as a throwable, so it's one long line with no frames. I'd always read that line as "the stack trace got cut off". It wasn't cut off. It was never logged.
Which is fine most of the time. The banner was written by someone who knew this failure, and the banner is often all you need. When it isn't, turn the trace back on (Section 6 has the switch).
The second thing to know is how messages chain. On Spring Framework 5.x (Boot 2.x), NestedRuntimeException.getMessage() appended the cause's message with ; nested exception is, so the top line of a Boot 2 trace contains the whole chain glued together, sometimes 2,000 characters wide. Framework 6 dropped that: NestedRuntimeException no longer overrides getMessage(). But the bean factory still builds its own messages by quoting the next failure down, which is why the top line in the example above still mentions rateCache. So the top line can give you a preview of the second level. It never reliably reaches the bottom.
And frames: most of the lines between Caused by blocks are the container calling itself, plus CGLIB proxy classes with $$SpringCGLIB$$ in their names and jdk.internal.reflect frames. They're framework noise for this purpose. The frames worth reading are your own packages and the first frame of the carrier.
From the last Caused by to the guilty bean
Here's the workflow I use now. It's slower to describe than to do.
- Find the first failure of the run, not the last. Restart loops and retries print the same trace many times, and later ones can be secondary (a context closing badly after the real failure).
grep -n -m1 'Application run failed\|APPLICATION FAILED TO START' app.loggets you the first one. - Jump to the last
Caused bybelow it. That's the carrier. Read its message and its firstatline. In the example:ConnectException: Connection refused, raised from the PostgreSQL driver's socket code. That's a network fact, not a Spring fact. - Walk up one or two levels for context, and stop.
PSQLExceptiontells you the host and port (fx-db:5432).CannotGetJdbcConnectionExceptiontells you it was a JDBC call.BeanCreationException ... 'rateCache': Invocation of init method failedtells you which bean made the call and when: in its init method, at startup. You now know what to fix (the host, the network, or the database's state) and why it happened at startup (a@PostConstructthat queries). - Ignore everything above that.
rateControlleris a bystander. - If you got a banner with no trace, turn on the reporter's DEBUG log and run again:
# application.properties, or the env var LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_BOOT_DIAGNOSTICS=debug
logging.level.org.springframework.boot.diagnostics=debug
That's the narrow switch: it only affects the failure reporter's package. Running with --debug also works, because it sets org.springframework.boot to DEBUG (I checked LoggingApplicationListener at the 3.5.0 tag), but it also prints the condition evaluation report and a lot of other DEBUG output.
- In tests, strip one more wrapper.
IllegalStateException: Failed to load ApplicationContextis the test framework telling you the context failed; the real chain starts at its firstCaused by. That wrapper gets its own article.
When is the bottom line not the answer? Two cases. First, when the carrier is generic and the context is one level up: NullPointerException at the bottom of a BeanCreationException ... Invocation of init method failed means your init method has a bug; the bean name one level up tells you whose. Second, when the bottom is a JVM error that's a symptom of packaging, like NoClassDefFoundError: the fix is in your build, not in the frame. The Java Errors series covers walking cause chains in general and those class-loading failures.
There's no fix to "cost" here, since nothing's broken in Spring. The cost is in the shortcuts. Catching Exception in a @PostConstruct and logging only e.getMessage() throws away every Caused by below it. I've seen that turn a refused connection into a log line that said Failed to obtain JDBC Connection and nothing else, and I'd rather you never see it.
Getting the structure right up front
A trace is as readable as the code that produced it. A few habits keep the chain short and honest:
- Always pass the cause when you rethrow.
throw new RateLoadException("Could not load rates for " + ccyPair, e), nevernew RateLoadException(e.getMessage()). The second one cuts the chain off at your class. - Don't do I/O in constructors or
@PostConstructunless startup genuinely needs it. Every startup-time call to a database or another service adds aBeanCreationExceptionand a bystander bean to the top of the trace. Warming a cache can run from anApplicationReadyEventlistener, after the context is up, where a failure is just a failure. - Log exceptions as exceptions.
log.error("Rate load failed for {}", pair, e)with the throwable as the last argument. SLF4J prints the full chain that way.
Here's what I'd write instead of the startup query from the example:
@Component
class RateCache {
private final RateRepository rates;
private volatile Map<String, BigDecimal> latest = Map.of();
RateCache(RateRepository rates) { this.rates = rates; }
@EventListener(ApplicationReadyEvent.class)
void warmUp() {
try {
latest = rates.loadLatest();
} catch (DataAccessException e) {
log.error("Rate warm-up failed; serving from source until next refresh", e); // full chain kept
}
}
}
Whether the app should refuse to start without the database is a separate decision. If it should, let it fail, and you'll at least get a trace with one fewer bystander in it.
Keeping the trace readable after the next upgrade
Some things changed recently enough to bite:
- Spring Framework 5.x / Boot 2.x:
; nested exception ischains in everyNestedRuntimeExceptionmessage. Wide top lines. - Spring Framework 6.0+ / Boot 3.0+: no automatic chaining in
getMessage(); bean-factory messages still quote one level down.NestedServletExceptionis gone too, so request-time traces start with a plainjakarta.servlet.ServletException: Request processing failed: ...and the cause underneath. - Boot 3.5+ structured logging: if you log JSON, you can control how traces are printed with
logging.structured.json.stacktrace.root=first(print the root cause first),max-length,max-throwable-depth,include-common-framesandinclude-hashes, per the Boot logging reference.root=firstis genuinely useful for anyone reading traces in a log UI that truncates long fields: the carrier is no longer the part that gets cut. Test it before shipping; a truncated trace with the root first is still truncated. - Boot 4.x (4.2.0 shipped 2026-11-19, on Framework 7.1):
StandardStackTracePrinterwithrootFirst()is in the 4.2 API docs. I read the banner-at-ERROR, trace-at-DEBUG split at the 3.5.0 tag; checkLoggingFailureAnalysisReporteragain whenever you cross a major.
Prevention is mostly a test. A @SpringBootTest that starts the real context against a Testcontainers database at your production version would have printed this exact chain in CI instead of in a pod. And if your log pipeline drops multi-line messages or truncates fields, check what it does to a 150-line trace before you need one. Lots of teams find out mid-incident that only the top line made it into the log UI.
A word on what I actually did for this one: I ran the JDK lab above, read SpringApplication, LoggingFailureAnalysisReporter, LoggingApplicationListener and AbstractApplicationContext at their release tags, compared NestedRuntimeException in Framework 5.3 and 6.2, and checked the Boot 3.5 logging reference and the 4.2 API docs. I didn't run a Boot app in this session, so the Spring-shaped trace at the top is a template built from source strings.
Screenshot this bit
- The last
Caused bynames the fault. The top line names whoever gave up last. - Wrappers (
UnsatisfiedDependencyException,BeanCreationException,Failed to load ApplicationContext) tell you where; the carrier tells you what. APPLICATION FAILED TO STARTwith no trace isn't a truncated log. Boot logs that trace at DEBUG; setlogging.level.org.springframework.boot.diagnostics=debugto see it.... 52 moremeans "same frames as above", not "lost frames".- Pass the cause every time you rethrow, or the next person's trace stops at your class.
Questions people type into Google about this
How do I find the root cause in a Spring Boot stack trace?
Scroll to the last line that starts with Caused by: under the first failure of the run. That's the root cause; its message and its first at frame tell you what broke. Then read one or two Caused by lines above it to learn which bean was involved. On a saved log, grep '^Caused by:' app.log | tail -1 finds it.
Why does Spring Boot show APPLICATION FAILED TO START without a stack trace?
A failure analyzer recognised the exception and printed a Description and Action instead. Boot logs the underlying stack trace at DEBUG from org.springframework.boot.diagnostics, so it's hidden by default. Set logging.level.org.springframework.boot.diagnostics=debug or run with --debug to see it (verified against Boot 3.5.0 source).
What does "... 52 more" mean in a Java stack trace?
It means the remaining 52 frames are identical to the bottom frames of the exception printed just above, so the JDK omits them. Nothing important is missing. The frames that differ, including the one where this exception was thrown, are printed above the ... N more line.
Is UnsatisfiedDependencyException the real error?
Almost never. It's the bean factory saying one bean couldn't be injected because a dependency failed. The real error is further down the chain, often a NoSuchBeanDefinitionException, a property binding failure or a connection error. The bean errors comparison shows how the wrappers nest.