use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class BindFailureAnalyzer method analyze.
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
if (CollectionUtils.isEmpty(cause.getAllErrors())) {
return null;
}
StringBuilder description = new StringBuilder(String.format("Binding to target %s failed:%n", cause.getTarget()));
for (ObjectError error : cause.getAllErrors()) {
if (error instanceof FieldError) {
FieldError fieldError = (FieldError) error;
description.append(String.format("%n Property: %s", cause.getObjectName() + "." + fieldError.getField()));
description.append(String.format("%n Value: %s", fieldError.getRejectedValue()));
}
description.append(String.format("%n Reason: %s%n", error.getDefaultMessage()));
}
return new FailureAnalysis(description.toString(), "Update your application's configuration", cause);
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class BindFailureAnalyzerTests method bindExceptionWithObjectErrorsDueToValidationFailure.
@Test
public void bindExceptionWithObjectErrorsDueToValidationFailure() throws Exception {
FailureAnalysis analysis = performAnalysis(ObjectValidationFailureConfiguration.class);
assertThat(analysis.getDescription()).contains("Reason: This object could not be bound.");
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForObjectProviderConstructorConsumer.
@Test
public void failureAnalysisForObjectProviderConstructorConsumer() {
FailureAnalysis failureAnalysis = analyzeFailure(createFailure(ObjectProviderConstructorConsumer.class));
assertThat(failureAnalysis.getDescription()).startsWith("Constructor in " + ObjectProviderConstructorConsumer.class.getName() + " required a single bean, but 6 were found:");
assertFoundBeans(failureAnalysis);
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForFieldConsumer.
@Test
public void failureAnalysisForFieldConsumer() {
FailureAnalysis failureAnalysis = analyzeFailure(createFailure(FieldConsumer.class));
assertThat(failureAnalysis.getDescription()).startsWith("Field testBean in " + FieldConsumer.class.getName() + " required a single bean, but 6 were found:");
assertFoundBeans(failureAnalysis);
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForXmlConsumer.
@Test
public void failureAnalysisForXmlConsumer() {
FailureAnalysis failureAnalysis = analyzeFailure(createFailure(XmlConsumer.class));
assertThat(failureAnalysis.getDescription()).startsWith("Parameter 0 of constructor in " + TestBeanConsumer.class.getName() + " required a single bean, but 6 were found:");
assertFoundBeans(failureAnalysis);
}
Aggregations