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
db3f488d
Commit
db3f488d
authored
Oct 12, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
03334169
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
26 deletions
+40
-26
EmbeddedDataSourceConfigurationTests.java
...oconfigure/jdbc/EmbeddedDataSourceConfigurationTests.java
+2
-3
MockitoPostProcessor.java
...ramework/boot/test/mock/mockito/MockitoPostProcessor.java
+4
-1
BeanCurrentlyInCreationFailureAnalyzer.java
...tics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
+34
-22
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationTests.java
View file @
db3f488d
...
...
@@ -56,14 +56,13 @@ public class EmbeddedDataSourceConfigurationTests {
@Test
public
void
generateUniqueName
()
throws
Exception
{
this
.
context
=
load
(
"spring.datasource.generate-unique-name=true"
);
AnnotationConfigApplicationContext
context2
=
load
(
"spring.datasource.generate-unique-name=true"
);
AnnotationConfigApplicationContext
context2
=
load
(
"spring.datasource.generate-unique-name=true"
);
try
{
DataSource
dataSource
=
this
.
context
.
getBean
(
DataSource
.
class
);
DataSource
dataSource2
=
context2
.
getBean
(
DataSource
.
class
);
assertThat
(
getDatabaseName
(
dataSource
))
.
isNotEqualTo
(
getDatabaseName
(
dataSource2
));
System
.
out
.
println
(
dataSource2
);
}
finally
{
context2
.
close
();
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java
View file @
db3f488d
...
...
@@ -478,8 +478,11 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
}
@Override
public
Object
postProcess
Before
Initialization
(
Object
bean
,
String
beanName
)
public
Object
postProcess
After
Initialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
if
(
bean
instanceof
FactoryBean
)
{
return
bean
;
}
return
createSpyIfNecessary
(
bean
,
beanName
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java
View file @
db3f488d
...
...
@@ -39,40 +39,42 @@ class BeanCurrentlyInCreationFailureAnalyzer
@Override
protected
FailureAnalysis
analyze
(
Throwable
rootFailure
,
BeanCurrentlyInCreationException
cause
)
{
List
<
BeanInCycle
>
beansInC
ycle
=
new
ArrayList
<
BeanInCycle
>();
List
<
BeanInCycle
>
c
ycle
=
new
ArrayList
<
BeanInCycle
>();
Throwable
candidate
=
rootFailure
;
int
cycleStart
=
-
1
;
while
(
candidate
!=
null
)
{
if
(
candidate
instanceof
BeanCreationException
)
{
BeanCreationException
creationEx
=
(
BeanCreationException
)
candidate
;
if
(
StringUtils
.
hasText
(
creationEx
.
getBeanName
()))
{
BeanInCycle
beanInCycle
=
new
BeanInCycle
(
creationEx
);
int
index
=
beansInCycle
.
indexOf
(
beanInCycle
);
if
(
index
==
-
1
)
{
beansInCycle
.
add
(
beanInCycle
);
}
else
{
cycleStart
=
index
;
}
BeanInCycle
beanInCycle
=
BeanInCycle
.
get
(
candidate
);
if
(
beanInCycle
!=
null
)
{
int
index
=
cycle
.
indexOf
(
beanInCycle
);
if
(
index
==
-
1
)
{
cycle
.
add
(
beanInCycle
);
}
cycleStart
=
(
cycleStart
==
-
1
?
index
:
cycleStart
);
}
candidate
=
candidate
.
getCause
();
}
String
message
=
buildMessage
(
cycle
,
cycleStart
);
return
new
FailureAnalysis
(
message
,
null
,
cause
);
}
private
String
buildMessage
(
List
<
BeanInCycle
>
beansInCycle
,
int
cycleStart
)
{
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
String
.
format
(
"The dependencies of some of the beans in the "
+
"application context form a cycle:%n%n"
));
for
(
int
i
=
0
;
i
<
beansInCycle
.
size
();
i
++)
{
BeanInCycle
beanInCycle
=
beansInCycle
.
get
(
i
);
if
(
i
==
cycleStart
)
{
message
.
append
(
String
.
format
(
"┌─────┐%n"
));
}
else
if
(
i
>
0
)
{
message
.
append
(
String
.
format
(
"%s ↓%n"
,
i
<
cycleStart
?
" "
:
"↑"
));
String
leftSide
=
(
i
<
cycleStart
?
" "
:
"↑"
);
message
.
append
(
String
.
format
(
"%s ↓%n"
,
leftSide
));
}
message
.
append
(
String
.
format
(
"%s %s%n"
,
i
<
cycleStart
?
" "
:
"|"
,
beansInCycle
.
get
(
i
)
));
String
leftSide
=
i
<
cycleStart
?
" "
:
"|"
;
message
.
append
(
String
.
format
(
"%s %s%n"
,
leftSide
,
beanInCycle
));
}
message
.
append
(
String
.
format
(
"└─────┘%n"
));
return
new
FailureAnalysis
(
message
.
toString
(),
null
,
cause
);
return
message
.
toString
(
);
}
private
static
final
class
BeanInCycle
{
...
...
@@ -114,14 +116,10 @@ class BeanCurrentlyInCreationFailureAnalyzer
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
)
{
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
()
)
{
return
false
;
}
if
(
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
BeanInCycle
other
=
(
BeanInCycle
)
obj
;
return
this
.
name
.
equals
(
other
.
name
);
return
this
.
name
.
equals
(((
BeanInCycle
)
obj
).
name
);
}
@Override
...
...
@@ -129,6 +127,20 @@ class BeanCurrentlyInCreationFailureAnalyzer
return
this
.
name
+
this
.
description
;
}
public
static
BeanInCycle
get
(
Throwable
ex
)
{
if
(
ex
instanceof
BeanCreationException
)
{
return
get
((
BeanCreationException
)
ex
);
}
return
null
;
}
private
static
BeanInCycle
get
(
BeanCreationException
ex
)
{
if
(
StringUtils
.
hasText
(
ex
.
getBeanName
()))
{
return
new
BeanInCycle
(
ex
);
}
return
null
;
}
}
}
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