From 6f70d53285698bd7d38a644824175c9b7e1cc2ca Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 2 Sep 2016 13:11:50 +0200 Subject: [PATCH] Add documentation for `FailureAnalyzer` Closes gh-6775 --- spring-boot-docs/src/main/asciidoc/howto.adoc | 24 +++++++++++++++++++ .../main/asciidoc/spring-boot-features.adoc | 23 ++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index a08c204754c..7eb14620882 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -22,6 +22,30 @@ can send us a {github-code}[pull request]. == Spring Boot application +[[howto-failure-analyzer]] +=== Create your own FailureAnalyzer +{dc-spring-boot}/diagnostics/FailureAnalyzer.{dc-ext}[[`FailureAnalyzer`] is a great way +to intercept an exception on startup and turn it into a human-readable message, wrapped +into a {dc-spring-boot}/diagnostics/FailureAnalysis.{dc-ext}[[`FailureAnalysis`]. Spring +Boot provides such analyzer for application context related exceptions, JSR-303 +validations and more. It is actually very easy to create your own. + +`AbstractFailureAnalyzer` is a convenient extension of `FailureAnalyzer` that checks the +presence of a specified exception type in the exception to handle. You can extend from +that so that your implementation gets a chance to handle the exception only when it is +actually present. If for whatever reason you can't handle the exception, return `null` +to let another implementation a chance to handle the exception. + +`FailureAnalyzer` implementations are to be registered in a `META-INF/spring.factories`: +the following registers `ProjectConstraintViolationFailureAnalyzer`: + +[source,properties,indent=0] +---- + org.springframework.boot.diagnostics.FailureAnalyzer=\ + com.example.ProjectConstraintViolationFailureAnalyzer +---- + + [[howto-troubleshoot-auto-configuration]] === Troubleshoot auto-configuration diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 3d32d44ba3e..3630218bbc1 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -46,6 +46,29 @@ When your application starts you should see something similar to the following: By default `INFO` logging messages will be shown, including some relevant startup details such as the user that launched the application. +If your application fails to start, registered `FailureAnalyzers` get a chance to provide +a dedicated error message and a concrete action to fix the problem. For instance if you +start a web application on port `8080` and that port is already in use, you should see +something similar to the following: + +[indent=0] +---- +*************************** +APPLICATION FAILED TO START +*************************** + +Description: + +Embedded servlet container 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. +---- + +NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can +<> very easily. + [[boot-features-banner]] === Customizing the Banner