Skip to content

Commit a6e59b3

Browse files
committed
Polish "Improve failure analysis with a single bean cycle"
See gh-26292
1 parent 044c902 commit a6e59b3

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,11 +70,12 @@ private String buildMessage(DependencyCycle dependencyCycle) {
7070
message.append(
7171
String.format("The dependencies of some of the beans in the application context form a cycle:%n%n"));
7272
List<BeanInCycle> beansInCycle = dependencyCycle.getBeansInCycle();
73+
boolean singleBean = beansInCycle.size() == 1;
7374
int cycleStart = dependencyCycle.getCycleStart();
7475
for (int i = 0; i < beansInCycle.size(); i++) {
7576
BeanInCycle beanInCycle = beansInCycle.get(i);
7677
if (i == cycleStart) {
77-
message.append(String.format((beansInCycle.size() == 1) ? "┌──->──┐%n" : "┌─────┐%n"));
78+
message.append(String.format(singleBean ? "┌──->──┐%n" : "┌─────┐%n"));
7879
}
7980
else if (i > 0) {
8081
String leftSide = (i < cycleStart) ? " " : "↑";
@@ -83,7 +84,7 @@ else if (i > 0) {
8384
String leftSide = (i < cycleStart) ? " " : "|";
8485
message.append(String.format("%s %s%n", leftSide, beanInCycle));
8586
}
86-
message.append(String.format((beansInCycle.size() == 1) ? "└──<-──┘%n" : "└─────┘%n"));
87+
message.append(String.format(singleBean ? "└──<-──┘%n" : "└─────┘%n"));
8788
return message.toString();
8889
}
8990

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,7 +150,6 @@ private Exception createFailure(Class<?> configuration) {
150150
}
151151

152152
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
153-
@SuppressWarnings("unused")
154153
static class CyclicBeanMethodsConfiguration {
155154

156155
@Bean
@@ -181,7 +180,6 @@ BeanOne one(BeanTwo two) {
181180
}
182181

183182
@Configuration(proxyBeanMethods = false)
184-
@SuppressWarnings("unused")
185183
static class CycleReferencedViaOtherBeansConfiguration {
186184

187185
@Bean
@@ -246,7 +244,6 @@ BeanTwo two() {
246244
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
247245
static class BeanThreeConfiguration {
248246

249-
@SuppressWarnings("unused")
250247
@Bean
251248
BeanThree three(BeanOne one) {
252249
return new BeanThree();
@@ -259,7 +256,6 @@ BeanThree three(BeanOne one) {
259256
@Configuration(proxyBeanMethods = false)
260257
static class SelfReferenceBeanConfiguration {
261258

262-
@SuppressWarnings("unused")
263259
@Bean
264260
SelfReferenceBean bean(SelfReferenceBean bean) {
265261
return new SelfReferenceBean();

0 commit comments

Comments
 (0)