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