Skip to content

Commit d3e06c4

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents cfee9ba + db3f488 commit d3e06c4

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ public void defaultEmbeddedDatabase() {
5656
@Test
5757
public void generateUniqueName() throws Exception {
5858
this.context = load("spring.datasource.generate-unique-name=true");
59-
AnnotationConfigApplicationContext context2 =
60-
load("spring.datasource.generate-unique-name=true");
59+
AnnotationConfigApplicationContext context2 = load(
60+
"spring.datasource.generate-unique-name=true");
6161
try {
6262
DataSource dataSource = this.context.getBean(DataSource.class);
6363
DataSource dataSource2 = context2.getBean(DataSource.class);
6464
assertThat(getDatabaseName(dataSource))
6565
.isNotEqualTo(getDatabaseName(dataSource2));
66-
System.out.println(dataSource2);
6766
}
6867
finally {
6968
context2.close();

spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ public Object getEarlyBeanReference(Object bean, String beanName)
478478
}
479479

480480
@Override
481-
public Object postProcessBeforeInitialization(Object bean, String beanName)
481+
public Object postProcessAfterInitialization(Object bean, String beanName)
482482
throws BeansException {
483+
if (bean instanceof FactoryBean) {
484+
return bean;
485+
}
483486
return createSpyIfNecessary(bean, beanName);
484487
}
485488

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

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,42 @@ class BeanCurrentlyInCreationFailureAnalyzer
3939
@Override
4040
protected FailureAnalysis analyze(Throwable rootFailure,
4141
BeanCurrentlyInCreationException cause) {
42-
List<BeanInCycle> beansInCycle = new ArrayList<BeanInCycle>();
42+
List<BeanInCycle> cycle = new ArrayList<BeanInCycle>();
4343
Throwable candidate = rootFailure;
4444
int cycleStart = -1;
4545
while (candidate != null) {
46-
if (candidate instanceof BeanCreationException) {
47-
BeanCreationException creationEx = (BeanCreationException) candidate;
48-
if (StringUtils.hasText(creationEx.getBeanName())) {
49-
BeanInCycle beanInCycle = new BeanInCycle(creationEx);
50-
int index = beansInCycle.indexOf(beanInCycle);
51-
if (index == -1) {
52-
beansInCycle.add(beanInCycle);
53-
}
54-
else {
55-
cycleStart = index;
56-
}
46+
BeanInCycle beanInCycle = BeanInCycle.get(candidate);
47+
if (beanInCycle != null) {
48+
int index = cycle.indexOf(beanInCycle);
49+
if (index == -1) {
50+
cycle.add(beanInCycle);
5751
}
52+
cycleStart = (cycleStart == -1 ? index : cycleStart);
5853
}
5954
candidate = candidate.getCause();
6055
}
56+
String message = buildMessage(cycle, cycleStart);
57+
return new FailureAnalysis(message, null, cause);
58+
}
59+
60+
private String buildMessage(List<BeanInCycle> beansInCycle, int cycleStart) {
6161
StringBuilder message = new StringBuilder();
6262
message.append(String.format("The dependencies of some of the beans in the "
6363
+ "application context form a cycle:%n%n"));
6464
for (int i = 0; i < beansInCycle.size(); i++) {
65+
BeanInCycle beanInCycle = beansInCycle.get(i);
6566
if (i == cycleStart) {
6667
message.append(String.format("┌─────┐%n"));
6768
}
6869
else if (i > 0) {
69-
message.append(String.format("%s ↓%n", i < cycleStart ? " " : "↑"));
70+
String leftSide = (i < cycleStart ? " " : "↑");
71+
message.append(String.format("%s ↓%n", leftSide));
7072
}
71-
message.append(String.format("%s %s%n", i < cycleStart ? " " : "|",
72-
beansInCycle.get(i)));
73+
String leftSide = i < cycleStart ? " " : "|";
74+
message.append(String.format("%s %s%n", leftSide, beanInCycle));
7375
}
7476
message.append(String.format("└─────┘%n"));
75-
return new FailureAnalysis(message.toString(), null, cause);
77+
return message.toString();
7678
}
7779

7880
private static final class BeanInCycle {
@@ -114,21 +116,31 @@ public boolean equals(Object obj) {
114116
if (this == obj) {
115117
return true;
116118
}
117-
if (obj == null) {
119+
if (obj == null || getClass() != obj.getClass()) {
118120
return false;
119121
}
120-
if (getClass() != obj.getClass()) {
121-
return false;
122-
}
123-
BeanInCycle other = (BeanInCycle) obj;
124-
return this.name.equals(other.name);
122+
return this.name.equals(((BeanInCycle) obj).name);
125123
}
126124

127125
@Override
128126
public String toString() {
129127
return this.name + this.description;
130128
}
131129

130+
public static BeanInCycle get(Throwable ex) {
131+
if (ex instanceof BeanCreationException) {
132+
return get((BeanCreationException) ex);
133+
}
134+
return null;
135+
}
136+
137+
private static BeanInCycle get(BeanCreationException ex) {
138+
if (StringUtils.hasText(ex.getBeanName())) {
139+
return new BeanInCycle(ex);
140+
}
141+
return null;
142+
}
143+
132144
}
133145

134146
}

0 commit comments

Comments
 (0)