Commit 3475e01c authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.4.x'

Closes gh-26323
parents 4febe648 4ccce2a7
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -70,11 +70,12 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea ...@@ -70,11 +70,12 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
message.append( message.append(
String.format("The dependencies of some of the beans in the application context form a cycle:%n%n")); String.format("The dependencies of some of the beans in the application context form a cycle:%n%n"));
List<BeanInCycle> beansInCycle = dependencyCycle.getBeansInCycle(); List<BeanInCycle> beansInCycle = dependencyCycle.getBeansInCycle();
boolean singleBean = beansInCycle.size() == 1;
int cycleStart = dependencyCycle.getCycleStart(); int cycleStart = dependencyCycle.getCycleStart();
for (int i = 0; i < beansInCycle.size(); i++) { for (int i = 0; i < beansInCycle.size(); i++) {
BeanInCycle beanInCycle = beansInCycle.get(i); BeanInCycle beanInCycle = beansInCycle.get(i);
if (i == cycleStart) { if (i == cycleStart) {
message.append(String.format("┌─────┐%n")); message.append(String.format(singleBean ? "┌──->──┐%n" : "┌─────┐%n"));
} }
else if (i > 0) { else if (i > 0) {
String leftSide = (i < cycleStart) ? " " : "↑"; String leftSide = (i < cycleStart) ? " " : "↑";
...@@ -83,7 +84,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea ...@@ -83,7 +84,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
String leftSide = (i < cycleStart) ? " " : "|"; String leftSide = (i < cycleStart) ? " " : "|";
message.append(String.format("%s %s%n", leftSide, beanInCycle)); message.append(String.format("%s %s%n", leftSide, beanInCycle));
} }
message.append(String.format("└─────┘%n")); message.append(String.format(singleBean ? "└──<-──┘%n" : "└─────┘%n"));
return message.toString(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -109,6 +109,19 @@ class BeanCurrentlyInCreationFailureAnalyzerTests { ...@@ -109,6 +109,19 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
assertThat(lines.get(11)).isEqualTo("└─────┘"); 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 @Test
void cycleWithAnUnknownStartIsNotAnalyzed() { void cycleWithAnUnknownStartIsNotAnalyzed() {
assertThat(this.analyzer.analyze(new BeanCurrentlyInCreationException("test"))).isNull(); assertThat(this.analyzer.analyze(new BeanCurrentlyInCreationException("test"))).isNull();
...@@ -240,6 +253,16 @@ class BeanCurrentlyInCreationFailureAnalyzerTests { ...@@ -240,6 +253,16 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
} }
@Configuration(proxyBeanMethods = false)
static class SelfReferenceBeanConfiguration {
@Bean
SelfReferenceBean bean(SelfReferenceBean bean) {
return new SelfReferenceBean();
}
}
static class RefererOne { static class RefererOne {
@Autowired @Autowired
...@@ -266,4 +289,11 @@ class BeanCurrentlyInCreationFailureAnalyzerTests { ...@@ -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