Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private String buildMessage(DependencyCycle dependencyCycle) {
for (int i = 0; i < beansInCycle.size(); i++) {
BeanInCycle beanInCycle = beansInCycle.get(i);
if (i == cycleStart) {
message.append(String.format("┌─────┐%n"));
message.append(String.format((beansInCycle.size() == 1) ? "┌──->──┐%n" : "┌─────┐%n"));
}
else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "↑";
Expand All @@ -83,7 +83,7 @@ else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "|";
message.append(String.format("%s %s%n", leftSide, beanInCycle));
}
message.append(String.format("└─────┘%n"));
message.append(String.format((beansInCycle.size() == 1) ? "└──<-──┘%n" : "└─────┘%n"));
return message.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ void cycleReferencedViaOtherBeans() throws IOException {
assertThat(lines.get(11)).isEqualTo("└─────┘");
}

@Test
void testSelfReferenceCycle() throws IOException {
FailureAnalysis analysis = performAnalysis(SelfReferenceBeanConfiguration.class);
List<String> lines = readDescriptionLines(analysis);
assertThat(lines).hasSize(5);
assertThat(lines.get(0))
.isEqualTo("The dependencies of some of the beans in the application context form a cycle:");
assertThat(lines.get(1)).isEqualTo("");
assertThat(lines.get(2)).isEqualTo("┌──->──┐");
assertThat(lines.get(3)).startsWith("| bean defined in " + SelfReferenceBeanConfiguration.class.getName());
assertThat(lines.get(4)).isEqualTo("└──<-──┘");
}

@Test
void cycleWithAnUnknownStartIsNotAnalyzed() {
assertThat(this.analyzer.analyze(new BeanCurrentlyInCreationException("test"))).isNull();
Expand Down Expand Up @@ -137,6 +150,7 @@ private Exception createFailure(Class<?> configuration) {
}

@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
@SuppressWarnings("unused")
static class CyclicBeanMethodsConfiguration {

@Bean
Expand Down Expand Up @@ -167,6 +181,7 @@ BeanOne one(BeanTwo two) {
}

@Configuration(proxyBeanMethods = false)
@SuppressWarnings("unused")
static class CycleReferencedViaOtherBeansConfiguration {

@Bean
Expand Down Expand Up @@ -231,6 +246,7 @@ BeanTwo two() {
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
static class BeanThreeConfiguration {

@SuppressWarnings("unused")
@Bean
BeanThree three(BeanOne one) {
return new BeanThree();
Expand All @@ -240,6 +256,17 @@ BeanThree three(BeanOne one) {

}

@Configuration(proxyBeanMethods = false)
static class SelfReferenceBeanConfiguration {

@SuppressWarnings("unused")
@Bean
SelfReferenceBean bean(SelfReferenceBean bean) {
return new SelfReferenceBean();
}

}

static class RefererOne {

@Autowired
Expand All @@ -266,4 +293,11 @@ static class BeanThree {

}

static class SelfReferenceBean {

@Autowired
SelfReferenceBean bean;

}

}