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
a082f2be
Commit
a082f2be
authored
Oct 07, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Investigating
parent
dfb660aa
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
10 deletions
+38
-10
SpringApplicationBuilder.java
...pringframework/boot/builder/SpringApplicationBuilder.java
+16
-7
ConfigFileApplicationContextInitializer.java
.../initializer/ConfigFileApplicationContextInitializer.java
+3
-3
SpringApplicationBuilderTests.java
...g/springframework/boot/SpringApplicationBuilderTests.java
+17
-0
application-node.properties
spring-boot/src/test/resources/application-node.properties
+1
-0
logback-test.xml
spring-boot/src/test/resources/logback-test.xml
+1
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java
View file @
a082f2be
...
...
@@ -99,7 +99,7 @@ public class SpringApplicationBuilder {
if
(
this
.
parent
!=
null
)
{
// If there is a parent initialize it and make sure it is added to the current
// context
addInitializers
(
new
ParentContextApplicationContextInitializer
(
addInitializers
(
true
,
new
ParentContextApplicationContextInitializer
(
this
.
parent
.
run
(
args
)));
}
...
...
@@ -111,6 +111,8 @@ public class SpringApplicationBuilder {
if
(
this
.
running
.
compareAndSet
(
false
,
true
))
{
synchronized
(
this
.
running
)
{
// If not already running copy the sources over and then run.
// this.application.setDefaultArgs(this.defaultArgs
// .toArray(new String[this.defaultArgs.size()]));
this
.
application
.
setSources
(
this
.
sources
);
this
.
context
=
this
.
application
.
run
(
args
);
}
...
...
@@ -190,7 +192,7 @@ public class SpringApplicationBuilder {
this
.
parent
=
new
SpringApplicationBuilder
();
this
.
parent
.
context
=
parent
;
this
.
parent
.
running
.
set
(
true
);
addInitializers
(
new
ParentContextApplicationContextInitializer
(
parent
));
addInitializers
(
true
,
new
ParentContextApplicationContextInitializer
(
parent
));
return
this
;
}
...
...
@@ -394,17 +396,24 @@ public class SpringApplicationBuilder {
*/
public
SpringApplicationBuilder
initializers
(
ApplicationContextInitializer
<?>...
initializers
)
{
addInitializers
(
initializers
);
addInitializers
(
false
,
initializers
);
return
this
;
}
/**
* @param initializers the initializers to add
*/
private
void
addInitializers
(
ApplicationContextInitializer
<?>...
initializers
)
{
Set
<
ApplicationContextInitializer
<?>>
target
=
new
LinkedHashSet
<
ApplicationContextInitializer
<?>>(
this
.
application
.
getInitializers
());
target
.
addAll
(
Arrays
.
asList
(
initializers
));
private
void
addInitializers
(
boolean
prepend
,
ApplicationContextInitializer
<?>...
initializers
)
{
Set
<
ApplicationContextInitializer
<?>>
target
=
new
LinkedHashSet
<
ApplicationContextInitializer
<?>>();
if
(
prepend
)
{
target
.
addAll
(
Arrays
.
asList
(
initializers
));
target
.
addAll
(
this
.
application
.
getInitializers
());
}
else
{
target
.
addAll
(
this
.
application
.
getInitializers
());
target
.
addAll
(
Arrays
.
asList
(
initializers
));
}
this
.
application
.
setInitializers
(
target
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/context/initializer/ConfigFileApplicationContextInitializer.java
View file @
a082f2be
...
...
@@ -171,7 +171,7 @@ public class ConfigFileApplicationContextInitializer implements
}
Resource
resource
=
resourceLoader
.
getResource
(
location
);
PropertySource
<?>
propertySource
=
getPropertySource
(
resource
,
loaders
);
PropertySource
<?>
propertySource
=
getPropertySource
(
resource
,
profile
,
loaders
);
if
(
propertySource
==
null
)
{
return
;
}
...
...
@@ -187,9 +187,9 @@ public class ConfigFileApplicationContextInitializer implements
environment
.
getPropertySources
().
addLast
(
propertySource
);
}
private
PropertySource
<?>
getPropertySource
(
Resource
resource
,
private
PropertySource
<?>
getPropertySource
(
Resource
resource
,
String
profile
,
List
<
PropertySourceLoader
>
loaders
)
{
String
key
=
resource
.
getDescription
();
String
key
=
resource
.
getDescription
()
+
(
profile
==
null
?
""
:
"#"
+
profile
)
;
if
(
this
.
cached
.
containsKey
(
key
))
{
return
this
.
cached
.
get
(
key
);
}
...
...
spring-boot/src/test/java/org/springframework/boot/SpringApplicationBuilderTests.java
View file @
a082f2be
...
...
@@ -87,6 +87,23 @@ public class SpringApplicationBuilderTests {
any
(
ApplicationContext
.
class
));
}
@Test
public
void
parentFirstCreationWithProfileAndDefaultArgs
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
profiles
(
"node"
).
defaultArgs
(
"--transport=redis"
)
.
child
(
ChildConfig
.
class
).
web
(
false
);
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
),
is
(
true
));
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"transport"
),
is
(
equalTo
(
"redis"
)));
assertThat
(
this
.
context
.
getParent
().
getEnvironment
().
acceptsProfiles
(
"node"
),
is
(
true
));
assertThat
(
this
.
context
.
getParent
().
getEnvironment
().
getProperty
(
"transport"
),
is
(
equalTo
(
"redis"
)));
// only defined in node profile
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"bar"
),
is
(
equalTo
(
"spam"
)));
}
@Test
public
void
parentContextIdentical
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
...
...
spring-boot/src/test/resources/application-node.properties
0 → 100644
View file @
a082f2be
bar
:
spam
\ No newline at end of file
spring-boot/src/test/resources/logback-test.xml
View file @
a082f2be
...
...
@@ -8,6 +8,7 @@
</encoder>
</appender>
<logger
name=
"org.springframework.boot.context.annotation"
level=
"TRACE"
/>
<logger
name=
"org.springframework.boot.context.initializer"
level=
"TRACE"
/>
<logger
name=
"org.springframework.boot.config"
level=
"TRACE"
/>
<logger
name=
"org.thymeleaf"
level=
"TRACE"
/>
<root
level=
"INFO"
>
...
...
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