From 50c68a497b1097643fde69d51a524b8903c2c547 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 16 Sep 2016 16:27:03 +0200 Subject: [PATCH] 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 --- ...ConfigurationReportLoggingInitializer.java | 12 ++++++++++-- .../main/asciidoc/spring-boot-features.adoc | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java index 331481ce929..240b1da25a9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.logging; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.boot.SpringBootVersion; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.logging.LogLevel; @@ -99,8 +100,8 @@ public class AutoConfigurationReportLoggingInitializer if (isCrashReport && this.logger.isInfoEnabled() && !this.logger.isDebugEnabled()) { this.logger.info(String.format("%n%nError starting ApplicationContext. " - + "To display the auto-configuration report enable " - + "debug logging (start with --debug)%n%n")); + + "To display the auto-configuration report re-run your application with debug enabled,%n" + + "see also %s%n%n", createStartupFailureDocUrl())); } if (this.logger.isDebugEnabled()) { 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 { @Override 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 f9ecaef4b59..109ce36ef5e 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,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 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 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 @@ -69,6 +74,20 @@ something similar to the following: NOTE: Spring Boot provides numerous `FailureAnalyzer` implementations and you can <> 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]]