parent
0e00a49dcc
commit
6f70d53285
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
<<howto.adoc#howto-failure-analyzer,add your own>> very easily.
|
||||
|
||||
|
||||
[[boot-features-banner]]
|
||||
=== Customizing the Banner
|
||||
|
|
|
|||
Loading…
Reference in New Issue