Explains a startup error that spring_boot_dart does not know, as an
APPLICATION FAILED TO START report instead of a stack trace.
A library that fails the start in a predictable way (a port already
in use, a database that cannot be reached, a missing licence key) can
tell the developer what happened and how to fix it. Declare the
analyzer as a bean (a starter puts it in its auto-configuration), or
pass it to SpringApplication(failureAnalyzers: ...). When the start
fails, the analyzers passed to the constructor are asked first, then
the beans sorted by @Order, then the built-in analysis; the first
non-null answer is reported. Analyzer beans are only found when the
context got far enough to create them.
analyze receives the error as it was thrown. An error raised while a
bean is created is often wrapped in a BeanCreationException, so walk
the cause chain when needed.
// The web server could not bind its port.
class PortInUseFailureAnalyzer implements FailureAnalyzer {
@override
FailureAnalysis? analyze(Object failure) => failure is PortInUseException
? FailureAnalysis(
'Port ${failure.port} is already in use.',
'Stop the other process or set server.port.',
failure,
)
: null;
}
Spring (Java):
class PortInUseFailureAnalyzer
extends AbstractFailureAnalyzer<PortInUseException> {
@Override
protected FailureAnalysis analyze(Throwable root, PortInUseException ex) {
return new FailureAnalysis("Port " + ex.getPort() + " is in use.",
"Stop the other process or set server.port.", ex);
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
analyze(
Object failure) → FailureAnalysis? -
An explanation of
failure, ornullwhen this analyzer does not recognise it and the next one should be asked. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited