File tree Expand file tree Collapse file tree
spring-boot/src/main/java/com/baeldung/failureanalyzer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import org .springframework .boot .diagnostics .AbstractFailureAnalyzer ;
55import 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}
You can’t perform that action at this time.
0 commit comments