diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java index 4e028fbbb0..a9c58a5039 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java @@ -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 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 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; + + } + }