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
d90647d7
Commit
d90647d7
authored
Oct 12, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
00af1f5c
ee3d4b34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
SpringApplicationBuilder.java
...pringframework/boot/builder/SpringApplicationBuilder.java
+16
-9
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+13
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java
View file @
d90647d7
...
...
@@ -59,6 +59,7 @@ import org.springframework.core.io.ResourceLoader;
* SpringApplication instead.
*
* @author Dave Syer
* @author Andy Wilkinson
*/
public
class
SpringApplicationBuilder
{
...
...
@@ -80,6 +81,8 @@ public class SpringApplicationBuilder {
private
boolean
registerShutdownHookApplied
;
private
boolean
configuredAsChild
=
false
;
public
SpringApplicationBuilder
(
Object
...
sources
)
{
this
.
application
=
createSpringApplication
(
sources
);
}
...
...
@@ -120,19 +123,11 @@ public class SpringApplicationBuilder {
* @return an application context created from the current state
*/
public
ConfigurableApplicationContext
run
(
String
...
args
)
{
if
(
this
.
parent
!=
null
)
{
// If there is a parent don't register a shutdown hook
if
(!
this
.
registerShutdownHookApplied
)
{
this
.
application
.
setRegisterShutdownHook
(
false
);
}
// initialize it and make sure it is added to the current context
initializers
(
new
ParentContextApplicationContextInitializer
(
this
.
parent
.
run
(
args
)));
}
if
(
this
.
running
.
get
())
{
// If already created we just return the existing context
return
this
.
context
;
}
configureAsChildIfNecessary
();
if
(
this
.
running
.
compareAndSet
(
false
,
true
))
{
synchronized
(
this
.
running
)
{
// If not already running copy the sources over and then run.
...
...
@@ -142,11 +137,23 @@ public class SpringApplicationBuilder {
return
this
.
context
;
}
private
void
configureAsChildIfNecessary
()
{
if
(
this
.
parent
!=
null
&&
!
this
.
configuredAsChild
)
{
this
.
configuredAsChild
=
true
;
if
(!
this
.
registerShutdownHookApplied
)
{
this
.
application
.
setRegisterShutdownHook
(
false
);
}
initializers
(
new
ParentContextApplicationContextInitializer
(
this
.
parent
.
run
()));
}
}
/**
* Returns a fully configured {@link SpringApplication} that is ready to run.
* @return the fully configured {@link SpringApplication}.
*/
public
SpringApplication
build
()
{
configureAsChildIfNecessary
();
this
.
application
.
setSources
(
this
.
sources
);
return
this
.
application
;
}
...
...
spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
d90647d7
...
...
@@ -98,7 +98,7 @@ public class SpringApplicationBuilderTests {
}
@Test
public
void
parentContextCreation
()
throws
Exception
{
public
void
parentContextCreation
ThatIsRunDirectly
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ChildConfig
.
class
).
contextClass
(
SpyApplicationContext
.
class
);
application
.
parent
(
ExampleConfig
.
class
);
...
...
@@ -109,6 +109,18 @@ public class SpringApplicationBuilderTests {
equalTo
(
false
));
}
@Test
public
void
parentContextCreationThatIsBuiltThenRun
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ChildConfig
.
class
).
contextClass
(
SpyApplicationContext
.
class
);
application
.
parent
(
ExampleConfig
.
class
);
this
.
context
=
application
.
build
().
run
();
verify
(((
SpyApplicationContext
)
this
.
context
).
getApplicationContext
())
.
setParent
(
any
(
ApplicationContext
.
class
));
assertThat
(((
SpyApplicationContext
)
this
.
context
).
getRegisteredShutdownHook
(),
equalTo
(
false
));
}
@Test
public
void
parentContextCreationWithChildShutdown
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
...
...
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