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
e10856fd
Commit
e10856fd
authored
Mar 11, 2014
by
Chris Beams
Committed by
Dave Syer
Mar 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SpringApplication Environment config hooks
Per discussion: fixes gh-467
parent
d4083e46
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
9 deletions
+29
-9
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+29
-9
No files found.
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
e10856fd
...
@@ -269,8 +269,7 @@ public class SpringApplication {
...
@@ -269,8 +269,7 @@ public class SpringApplication {
try
{
try
{
// Create and configure the environment
// Create and configure the environment
ConfigurableEnvironment
environment
=
getOrCreateEnvironment
();
ConfigurableEnvironment
environment
=
getOrCreateEnvironment
();
addPropertySources
(
environment
,
args
);
configureEnvironment
(
environment
,
args
);
setupProfiles
(
environment
);
for
(
SpringApplicationRunListener
runListener
:
runListeners
)
{
for
(
SpringApplicationRunListener
runListener
:
runListeners
)
{
runListener
.
environmentPrepared
(
environment
);
runListener
.
environmentPrepared
(
environment
);
}
}
...
@@ -382,11 +381,28 @@ public class SpringApplication {
...
@@ -382,11 +381,28 @@ public class SpringApplication {
}
}
/**
/**
* Add any {@link PropertySource}s to the environment.
* Template method delegating to
* @param environment the environment
* {@link #configurePropertySources(ConfigurableEnvironment, String[])} and
* @param args run arguments
* {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. Override
* this method for complete control over Environment customization, or one of the above
* for fine-grained control over property sources or profiles, respectively.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configurePropertySources(ConfigurableEnvironment, String[])
* @see #configureProfiles(ConfigurableEnvironment, String[])
*/
protected
void
configureEnvironment
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
configurePropertySources
(
environment
,
args
);
configureProfiles
(
environment
,
args
);
}
/**
* Add, remove or re-order any {@link PropertySource}s in this application's environment.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
*/
protected
void
add
PropertySources
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
protected
void
configure
PropertySources
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
MutablePropertySources
sources
=
environment
.
getPropertySources
();
MutablePropertySources
sources
=
environment
.
getPropertySources
();
if
(
this
.
defaultProperties
!=
null
&&
!
this
.
defaultProperties
.
isEmpty
())
{
if
(
this
.
defaultProperties
!=
null
&&
!
this
.
defaultProperties
.
isEmpty
())
{
sources
.
addLast
(
new
MapPropertySource
(
"defaultProperties"
,
sources
.
addLast
(
new
MapPropertySource
(
"defaultProperties"
,
...
@@ -409,10 +425,14 @@ public class SpringApplication {
...
@@ -409,10 +425,14 @@ public class SpringApplication {
}
}
/**
/**
* Setup any active profiles on the environment.
* Configure which profiles are active (or active by default) for this application environment.
* @param environment the environment to configure
* Consider overriding this method to programmatically enforce profile rules and semantics,
* such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR 'prod', but never both).
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
*/
protected
void
setupProfiles
(
ConfigurableEnvironment
environment
)
{
protected
void
configureProfiles
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
Set
<
String
>
profiles
=
new
LinkedHashSet
<
String
>();
Set
<
String
>
profiles
=
new
LinkedHashSet
<
String
>();
environment
.
getActiveProfiles
();
// ensure they are initialized
environment
.
getActiveProfiles
();
// ensure they are initialized
// But these ones should go first (last wins in a property key clash)
// But these ones should go first (last wins in a property key clash)
...
...
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