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
8c1820af
Commit
8c1820af
authored
Jun 02, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
a00ad728
b9a09fcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
+46
-6
BeanCurrentlyInCreationFailureAnalyzer.java
...tics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
+39
-6
BeanCurrentlyInCreationFailureAnalyzerTests.java
...analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java
+7
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
View file @
8c1820af
...
...
@@ -39,28 +39,40 @@ class BeanCurrentlyInCreationFailureAnalyzer
@Override
protected
FailureAnalysis
analyze
(
Throwable
rootFailure
,
BeanCurrentlyInCreationException
cause
)
{
List
<
BeanInCycle
>
cycle
=
new
ArrayList
<>();
DependencyCycle
dependencyCycle
=
findCycle
(
rootFailure
);
if
(
dependencyCycle
==
null
)
{
return
null
;
}
return
new
FailureAnalysis
(
buildMessage
(
dependencyCycle
),
null
,
cause
);
}
private
DependencyCycle
findCycle
(
Throwable
rootFailure
)
{
List
<
BeanInCycle
>
beansInCycle
=
new
ArrayList
<>();
Throwable
candidate
=
rootFailure
;
int
cycleStart
=
-
1
;
while
(
candidate
!=
null
)
{
BeanInCycle
beanInCycle
=
BeanInCycle
.
get
(
candidate
);
if
(
beanInCycle
!=
null
)
{
int
index
=
c
ycle
.
indexOf
(
beanInCycle
);
int
index
=
beansInC
ycle
.
indexOf
(
beanInCycle
);
if
(
index
==
-
1
)
{
c
ycle
.
add
(
beanInCycle
);
beansInC
ycle
.
add
(
beanInCycle
);
}
cycleStart
=
(
cycleStart
==
-
1
?
index
:
cycleStart
);
}
candidate
=
candidate
.
getCause
();
}
String
message
=
buildMessage
(
cycle
,
cycleStart
);
return
new
FailureAnalysis
(
message
,
null
,
cause
);
if
(
cycleStart
==
-
1
)
{
return
null
;
}
return
new
DependencyCycle
(
beansInCycle
,
cycleStart
);
}
private
String
buildMessage
(
List
<
BeanInCycle
>
beansInCycle
,
int
cycleStart
)
{
private
String
buildMessage
(
DependencyCycle
dependencyCycle
)
{
StringBuilder
message
=
new
StringBuilder
();
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
();
int
cycleStart
=
dependencyCycle
.
getCycleStart
();
for
(
int
i
=
0
;
i
<
beansInCycle
.
size
();
i
++)
{
BeanInCycle
beanInCycle
=
beansInCycle
.
get
(
i
);
if
(
i
==
cycleStart
)
{
...
...
@@ -77,6 +89,27 @@ class BeanCurrentlyInCreationFailureAnalyzer
return
message
.
toString
();
}
private
static
final
class
DependencyCycle
{
private
final
List
<
BeanInCycle
>
beansInCycle
;
private
final
int
cycleStart
;
private
DependencyCycle
(
List
<
BeanInCycle
>
beansInCycle
,
int
cycleStart
)
{
this
.
beansInCycle
=
beansInCycle
;
this
.
cycleStart
=
cycleStart
;
}
public
List
<
BeanInCycle
>
getBeansInCycle
()
{
return
this
.
beansInCycle
;
}
public
int
getCycleStart
()
{
return
this
.
cycleStart
;
}
}
private
static
final
class
BeanInCycle
{
private
final
String
name
;
...
...
spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java
View file @
8c1820af
...
...
@@ -24,6 +24,7 @@ import java.util.List;
import
org.junit.Test
;
import
org.springframework.beans.factory.BeanCurrentlyInCreationException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
org.springframework.boot.diagnostics.FailureAnalyzer
;
...
...
@@ -116,6 +117,12 @@ public class BeanCurrentlyInCreationFailureAnalyzerTests {
assertThat
(
lines
.
get
(
11
)).
isEqualTo
(
"└─────┘"
);
}
@Test
public
void
cycleWithAnUnknownStartIsNotAnalyzed
()
throws
IOException
{
assertThat
(
this
.
analyzer
.
analyze
(
new
BeanCurrentlyInCreationException
(
"test"
)))
.
isNull
();
}
private
List
<
String
>
readDescriptionLines
(
FailureAnalysis
analysis
)
throws
IOException
{
try
(
BufferedReader
lineReader
=
new
BufferedReader
(
...
...
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