Skip to content

Commit 4d08f3d

Browse files
pivovaritKevinGilmore
authored andcommitted
Refactor Analyzer examples (eugenp#1579)
* Refactor Analyzer examples * Refactor Analyzer examples
1 parent 0f67389 commit 4d08f3d

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎spring-boot/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
55
import org.springframework.boot.diagnostics.FailureAnalysis;
66

7-
public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
7+
public class MyBeanNotOfRequiredTypeFailureAnalyzer
8+
extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
89

910
@Override
1011
protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeException cause) {
1112
return new FailureAnalysis(getDescription(cause), getAction(cause), cause);
1213
}
1314

1415
private String getDescription(BeanNotOfRequiredTypeException ex) {
15-
return "The bean " + ex.getBeanName() //
16-
+ " could not be injected as " + ex.getRequiredType().getName() //
17-
+ " because it is of type " + ex.getActualType().getName();
16+
return String.format("The bean %s could not be injected as %s because it is of type %s",
17+
ex.getBeanName(),
18+
ex.getRequiredType().getName(),
19+
ex.getActualType().getName());
1820
}
1921

2022
private String getAction(BeanNotOfRequiredTypeException ex) {
21-
return "Consider creating a bean with name "+ ex.getBeanName() //
22-
+ " of type " + ex.getRequiredType().getName();
23+
return String.format("Consider creating a bean with name %s of type %s",
24+
ex.getBeanName(),
25+
ex.getRequiredType().getName());
2326
}
2427

2528
}

0 commit comments

Comments
 (0)