A FailureAnalyzer recognizes a specific startup exception and supplies a focused description and repair action without swallowing the failure.
Spring Boot FailureAnalyzer: turn one startup exception into an actionable failure
Analyze one failure family
A receipt service refuses to start when its ledger schema version is unsupported. A custom analyzer can recognize that domain exception and name the incompatible version in the startup report. It must return null for unrelated failures so another analyzer or the original stack trace can handle them. The analyzer changes diagnosis, not the process outcome. Startup validation] still prevents an unsafe service from accepting traffic.
Register before the context exists
A startup failure may occur before ordinary beans are available, so registering the analyzer as an application bean is not a safe discovery strategy. Package its implementation name under the FailureAnalyzer key in META-INF/spring.factories. Keep its constructor light; avoid database queries, secrets and network calls inside error reporting. If the exception contains a password or connection string, redact that information before creating the description. The condition report] is better for missing auto-configuration than a domain-specific analyzer.
Prove both branches
Start a small application with an unsupported ledger version and capture the failure report. Check that the report names the expected version and a precise repair step, then assert startup still exits unsuccessfully. Trigger an unrelated bean creation error and confirm this analyzer does not claim it. A diagnostic that turns every exception into a generic ledger message costs more time than it saves.
Implementation contract
final class LedgerVersionAnalyzer
extends AbstractFailureAnalyzer<UnsupportedLedgerVersionException> {
@Override protected FailureAnalysis analyze(
Throwable rootFailure, UnsupportedLedgerVersionException cause) {
return new FailureAnalysis(
"Receipt ledger schema " + cause.schemaVersion() + " is unsupported",
"Run the approved ledger migration before starting this service",
rootFailure);
}
}Cost and verification
An analyzer runs only on startup failure. Its operational cost is inaccurate advice or leaked secrets, not request latency.
Common Mistakes
- Do not treat an analyzer as a recovery mechanism that permits unsafe startup.
- Do not register it only as a normal application bean.
- Do not echo credentials from the exception into the report.
Read next
Spring Boot configuration validation: reject an unusable relay before work starts, Spring Boot condition report: locate the missing auto-configuration decision, Spring Boot runner failure: reject startup instead of accepting unsafe settings, Spring Boot process exit codes: make job failure visible to the scheduler, Spring Boot and Flyway: choose who runs migrations before traffic starts.
