What is a Spring Boot FailureAnalyzer, and what produces the "APPLICATION FAILED TO START" message you see when startup fails?
answer
- APPLICATION FAILED TO START banner
- Description + Action from FailureAnalysis
- startup exceptions, not runtime
- no match -> plain stack trace
- LoggingFailureAnalysisReporter prints it
basics
~20 sA FailureAnalyzer turns a startup exception into a friendly error with a Description and an Action to fix it. Spring Boot prints these as the "APPLICATION FAILED TO START" banner instead of a raw stack trace.
solid answer
~30 sWhen a Spring Boot app fails during startup, instead of just dumping a stack trace, Spring runs a set of FailureAnalyzers. A FailureAnalyzer inspects the thrown exception and, if it recognizes it, returns a FailureAnalysis containing a human-readable Description (what went wrong) and an Action (how to fix it). Spring Boot's LoggingFailureAnalysisReporter then prints these under the "APPLICATION FAILED TO START" banner. Boot ships many built-in analyzers — e.g. for a port already in use, a missing required bean, or invalid configuration properties. If no analyzer matches, you fall back to the normal stack trace.
go deeper
Know it turns ugly startup errors into a Description + Action banner.
Name the FailureAnalyzer/FailureAnalysis pieces and a couple of built-in analyzers.
Explain it only fires on startup failure and falls back to a stack trace when nothing matches.
Frame it as part of Boot's operator-friendly startup diagnostics and where it plugs into the SpringApplication lifecycle.
## The problem it solves Raw Java stack traces are hard to read, especially for common, boring startup failures like "port 8080 already in use" or "required bean not found." Spring Boot's **diagnostics** system (package `org.springframework.boot.diagnostics`) intercepts a fatal startup exception and tries to translate it into a clear, actionable message. ## The banner When you see: ``` *************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. ``` ...that whole block is produced by the diagnostics machinery, **not** by your own code. The **Description** and **Action** sections come from a `FailureAnalysis` object, and the banner + formatting come from `LoggingFailureAnalysisReporter` (the default `FailureAnalysisReporter`). ## Key pieces (vocabulary) - **`FailureAnalyzer`** — an interface with one method, `FailureAnalysis analyze(Throwable failure)`. Each analyzer knows how to recognize one kind of failure. - **`FailureAnalysis`** — a small value object holding three things: a `description` (what happened), an `action` (what you should do), and the original `cause` throwable. - **`FailureAnalysisReporter`** — decides how to present the analysis; the default logs the banner. ## When it runs This only kicks in for failures during application startup (context refresh / web server start), reported by `SpringApplication`. It does **not** intercept exceptions at runtime after the app is up. ## Built-in examples Boot provides analyzers for many common cases: `WebServerPortInUseFailureAnalyzer` (port taken), `NoSuchBeanDefinitionFailureAnalyzer` (a required dependency has no bean), `NoUniqueBeanDefinitionFailureAnalyzer` (two candidates for one injection point), `BindFailureAnalyzer` / `BindValidationFailureAnalyzer` (bad `@ConfigurationProperties` values), and `BeanCurrentlyInCreationFailureAnalyzer` (circular reference). ## Gotcha If **no** analyzer recognizes the exception, you get the plain stack trace — so the absence of a nice banner just means no analyzer matched, not that diagnostics is broken.
- If you don't see the banner and just get a stack trace, what does that mean?No registered FailureAnalyzer recognized that exception type, so Boot fell back to printing the raw stack trace. The diagnostics system still ran; it just had nothing to say.