Commit 4ccce2a7 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.3.x' into 2.4.x

Closes gh-26322
parents 63d48615 1af7fa22
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -70,11 +70,12 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
message.append(
String.format("The dependencies of some of the beans in the application context form a cycle:%n%n"));
List<BeanInCycle> beansInCycle = dependencyCycle.getBeansInCycle();
boolean singleBean = beansInCycle.size() == 1;
int cycleStart = dependencyCycle.getCycleStart();
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(singleBean ? "┌──->──┐%n" : "┌─────┐%n"));
}
else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "↑";
......@@ -83,7 +84,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
String leftSide = (i < cycleStart) ? " " : "|";
message.append(String.format("%s %s%n", leftSide, beanInCycle));
}
message.append(String.format("└─────┘%n"));
message.append(String.format(singleBean ? "└──<-──┘%n" : "└─────┘%n"));
return message.toString();
}
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -109,6 +109,19 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
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();
......@@ -240,6 +253,16 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
@Configuration(proxyBeanMethods = false)
static class SelfReferenceBeanConfiguration {
@Bean
SelfReferenceBean bean(SelfReferenceBean bean) {
return new SelfReferenceBean();
}
}
static class RefererOne {
@Autowired
......@@ -266,4 +289,11 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
static class SelfReferenceBean {
@Autowired
SelfReferenceBean bean;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment