Improve startup error message
This commit improves the startup error message so that it does not reference `--debug` anymore. Such command-line switch only works when the application is started using `java -jar`. The error message now refers directly to a section of the documentation that provides more details and links to more useful examples. Closes gh-6593
This commit is contained in:
parent
78bb04f2c1
commit
50c68a497b
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.logging;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringBootVersion;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||||
import org.springframework.boot.logging.LogLevel;
|
import org.springframework.boot.logging.LogLevel;
|
||||||
|
@ -99,8 +100,8 @@ public class AutoConfigurationReportLoggingInitializer
|
||||||
if (isCrashReport && this.logger.isInfoEnabled()
|
if (isCrashReport && this.logger.isInfoEnabled()
|
||||||
&& !this.logger.isDebugEnabled()) {
|
&& !this.logger.isDebugEnabled()) {
|
||||||
this.logger.info(String.format("%n%nError starting ApplicationContext. "
|
this.logger.info(String.format("%n%nError starting ApplicationContext. "
|
||||||
+ "To display the auto-configuration report enable "
|
+ "To display the auto-configuration report re-run your application with debug enabled,%n"
|
||||||
+ "debug logging (start with --debug)%n%n"));
|
+ "see also %s%n%n", createStartupFailureDocUrl()));
|
||||||
}
|
}
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger.debug(new ConditionEvaluationReportMessage(this.report));
|
this.logger.debug(new ConditionEvaluationReportMessage(this.report));
|
||||||
|
@ -108,6 +109,13 @@ public class AutoConfigurationReportLoggingInitializer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createStartupFailureDocUrl() {
|
||||||
|
String bootVersion = SpringBootVersion.getVersion();
|
||||||
|
String version = bootVersion != null ? bootVersion : "current";
|
||||||
|
return String.format(
|
||||||
|
"http://docs.spring.io/spring-boot/docs/%s/reference/html/boot-features-spring-application.html#boot-features-startup-failure", version);
|
||||||
|
}
|
||||||
|
|
||||||
private class AutoConfigurationReportListener implements GenericApplicationListener {
|
private class AutoConfigurationReportListener implements GenericApplicationListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,6 +46,11 @@ 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
|
By default `INFO` logging messages will be shown, including some relevant startup details
|
||||||
such as the user that launched the application.
|
such as the user that launched the application.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[boot-features-startup-failure]
|
||||||
|
=== Startup failure
|
||||||
|
|
||||||
If your application fails to start, registered `FailureAnalyzers` get a chance to provide
|
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
|
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
|
start a web application on port `8080` and that port is already in use, you should see
|
||||||
|
@ -69,6 +74,20 @@ something similar to the following:
|
||||||
NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can
|
NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can
|
||||||
<<howto.adoc#howto-failure-analyzer,add your own>> very easily.
|
<<howto.adoc#howto-failure-analyzer,add your own>> very easily.
|
||||||
|
|
||||||
|
If no failure analyzers are able to handle the exception, you can still display the full
|
||||||
|
auto-configuration report to better understand what went wrong. To do so you need to
|
||||||
|
<<#boot-features-external-config,enable the `debug` property>> or
|
||||||
|
<<#boot-features-custom-log-levels,enable `DEBUG` logging>> for
|
||||||
|
`org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer`.
|
||||||
|
|
||||||
|
For instance, if you are running your application using `java -jar` you can enable the
|
||||||
|
`debug` property as follows:
|
||||||
|
|
||||||
|
[indent=0,subs="attributes"]
|
||||||
|
----
|
||||||
|
$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[boot-features-banner]]
|
[[boot-features-banner]]
|
||||||
|
|
Loading…
Reference in New Issue