Refactor Analyzer examples (#1579)

* Refactor Analyzer examples

* Refactor Analyzer examples
This commit is contained in:
Grzegorz Piwowarek 2017-04-03 16:14:11 +02:00 committed by KevinGilmore
parent 0f673891a6
commit 4d08f3db6d

View File

@ -4,7 +4,8 @@ import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
public class MyBeanNotOfRequiredTypeFailureAnalyzer
extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeException cause) {
@ -12,14 +13,16 @@ public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnaly
}
private String getDescription(BeanNotOfRequiredTypeException ex) {
return "The bean " + ex.getBeanName() //
+ " could not be injected as " + ex.getRequiredType().getName() //
+ " because it is of type " + ex.getActualType().getName();
return String.format("The bean %s could not be injected as %s because it is of type %s",
ex.getBeanName(),
ex.getRequiredType().getName(),
ex.getActualType().getName());
}
private String getAction(BeanNotOfRequiredTypeException ex) {
return "Consider creating a bean with name "+ ex.getBeanName() //
+ " of type " + ex.getRequiredType().getName();
return String.format("Consider creating a bean with name %s of type %s",
ex.getBeanName(),
ex.getRequiredType().getName());
}
}