Polish "Improve failure analysis with a single bean cycle"

See gh-26292
This commit is contained in:
Stephane Nicoll 2021-04-30 13:29:23 +02:00
parent 044c902a8c
commit a6e59b357f
2 changed files with 5 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* 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((beansInCycle.size() == 1) ? "┌──->──┐%n" : "┌─────┐%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((beansInCycle.size() == 1) ? "└──<-──┘%n" : "└─────┘%n"));
message.append(String.format(singleBean ? "└──<-──┘%n" : "└─────┘%n"));
return message.toString();
}

View File

@ -1,5 +1,5 @@
/*
* 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.
@ -150,7 +150,6 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
@SuppressWarnings("unused")
static class CyclicBeanMethodsConfiguration {
@Bean
@ -181,7 +180,6 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
@Configuration(proxyBeanMethods = false)
@SuppressWarnings("unused")
static class CycleReferencedViaOtherBeansConfiguration {
@Bean
@ -246,7 +244,6 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
static class BeanThreeConfiguration {
@SuppressWarnings("unused")
@Bean
BeanThree three(BeanOne one) {
return new BeanThree();
@ -259,7 +256,6 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
@Configuration(proxyBeanMethods = false)
static class SelfReferenceBeanConfiguration {
@SuppressWarnings("unused")
@Bean
SelfReferenceBean bean(SelfReferenceBean bean) {
return new SelfReferenceBean();