Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
044c902a
Commit
044c902a
authored
Apr 28, 2021
by
Roman Zabaluev
Committed by
Stephane Nicoll
Apr 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve failure analysis with a single bean cycle
See gh-26292
parent
3f528bb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
BeanCurrentlyInCreationFailureAnalyzer.java
...tics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
+2
-2
BeanCurrentlyInCreationFailureAnalyzerTests.java
...analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java
+34
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
View file @
044c902a
...
@@ -74,7 +74,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
...
@@ -74,7 +74,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
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
(
(
beansInCycle
.
size
()
==
1
)
?
"┌──->──┐%n"
:
"┌─────┐%n"
));
}
}
else
if
(
i
>
0
)
{
else
if
(
i
>
0
)
{
String
leftSide
=
(
i
<
cycleStart
)
?
" "
:
"↑"
;
String
leftSide
=
(
i
<
cycleStart
)
?
" "
:
"↑"
;
...
@@ -83,7 +83,7 @@ class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<Bea
...
@@ -83,7 +83,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
(
(
beansInCycle
.
size
()
==
1
)
?
"└──<-──┘%n"
:
"└─────┘%n"
));
return
message
.
toString
();
return
message
.
toString
();
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java
View file @
044c902a
...
@@ -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
();
...
@@ -137,6 +150,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
...
@@ -137,6 +150,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
}
@org
.
springframework
.
context
.
annotation
.
Configuration
(
proxyBeanMethods
=
false
)
@org
.
springframework
.
context
.
annotation
.
Configuration
(
proxyBeanMethods
=
false
)
@SuppressWarnings
(
"unused"
)
static
class
CyclicBeanMethodsConfiguration
{
static
class
CyclicBeanMethodsConfiguration
{
@Bean
@Bean
...
@@ -167,6 +181,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
...
@@ -167,6 +181,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
@SuppressWarnings
(
"unused"
)
static
class
CycleReferencedViaOtherBeansConfiguration
{
static
class
CycleReferencedViaOtherBeansConfiguration
{
@Bean
@Bean
...
@@ -231,6 +246,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
...
@@ -231,6 +246,7 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
@org
.
springframework
.
context
.
annotation
.
Configuration
(
proxyBeanMethods
=
false
)
@org
.
springframework
.
context
.
annotation
.
Configuration
(
proxyBeanMethods
=
false
)
static
class
BeanThreeConfiguration
{
static
class
BeanThreeConfiguration
{
@SuppressWarnings
(
"unused"
)
@Bean
@Bean
BeanThree
three
(
BeanOne
one
)
{
BeanThree
three
(
BeanOne
one
)
{
return
new
BeanThree
();
return
new
BeanThree
();
...
@@ -240,6 +256,17 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
...
@@ -240,6 +256,17 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
SelfReferenceBeanConfiguration
{
@SuppressWarnings
(
"unused"
)
@Bean
SelfReferenceBean
bean
(
SelfReferenceBean
bean
)
{
return
new
SelfReferenceBean
();
}
}
static
class
RefererOne
{
static
class
RefererOne
{
@Autowired
@Autowired
...
@@ -266,4 +293,11 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
...
@@ -266,4 +293,11 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
}
}
static
class
SelfReferenceBean
{
@Autowired
SelfReferenceBean
bean
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment