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
16d4214f
Commit
16d4214f
authored
Mar 17, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a couple more tests on profile ordering
parent
b8d85dec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
4 deletions
+33
-4
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+1
-1
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+3
-0
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+15
-2
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+14
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
16d4214f
...
@@ -388,8 +388,8 @@ public class SpringApplication {
...
@@ -388,8 +388,8 @@ public class SpringApplication {
* the above for fine-grained control over property sources or profiles, respectively.
* the above for fine-grained control over property sources or profiles, respectively.
* @param environment this application's environment
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @param args arguments passed to the {@code run} method
* @see #configurePropertySources(ConfigurableEnvironment, String[])
* @see #configureProfiles(ConfigurableEnvironment, String[])
* @see #configureProfiles(ConfigurableEnvironment, String[])
* @see #configurePropertySources(ConfigurableEnvironment, String[])
*/
*/
protected
void
configureEnvironment
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
protected
void
configureEnvironment
(
ConfigurableEnvironment
environment
,
String
[]
args
)
{
configurePropertySources
(
environment
,
args
);
configurePropertySources
(
environment
,
args
);
...
...
spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
16d4214f
...
@@ -285,6 +285,9 @@ public class ConfigFileApplicationListener implements
...
@@ -285,6 +285,9 @@ public class ConfigFileApplicationListener implements
this
.
profiles
.
addAll
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()));
this
.
profiles
.
addAll
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()));
}
}
// The default profile for these purposes is represented as null. We add it
// last so that it is first out (active profiles will then override any
// settings in the defaults when the list is reversed later).
this
.
profiles
.
add
(
null
);
this
.
profiles
.
add
(
null
);
while
(!
this
.
profiles
.
isEmpty
())
{
while
(!
this
.
profiles
.
isEmpty
())
{
...
...
spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
16d4214f
...
@@ -296,9 +296,22 @@ public class SpringApplicationTests {
...
@@ -296,9 +296,22 @@ public class SpringApplicationTests {
application
.
setAdditionalProfiles
(
"foo"
);
application
.
setAdditionalProfiles
(
"foo"
);
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
application
.
setEnvironment
(
environment
);
application
.
setEnvironment
(
environment
);
application
.
run
(
"--spring.profiles.active=bar"
);
application
.
run
(
"--spring.profiles.active=bar
,spam
"
);
// Command line should always come last
// Command line should always come last
assertArrayEquals
(
new
String
[]
{
"foo"
,
"bar"
},
environment
.
getActiveProfiles
());
assertArrayEquals
(
new
String
[]
{
"foo"
,
"bar"
,
"spam"
},
environment
.
getActiveProfiles
());
}
@Test
public
void
addProfilesOrderWithProperties
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setWebEnvironment
(
false
);
application
.
setAdditionalProfiles
(
"other"
);
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
application
.
setEnvironment
(
environment
);
application
.
run
();
// Active profile should win over default
assertEquals
(
"fromotherpropertiesfile"
,
environment
.
getProperty
(
"my.property"
));
}
}
@Test
@Test
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
16d4214f
...
@@ -189,7 +189,20 @@ public class ConfigFileApplicationListenerTests {
...
@@ -189,7 +189,20 @@ public class ConfigFileApplicationListenerTests {
}
}
@Test
@Test
public
void
loadPropertiesThenProfileProperties
()
throws
Exception
{
public
void
loadPropertiesThenProfilePropertiesActivatedInSpringApplication
()
throws
Exception
{
// This should be the effect of calling
// SpringApplication.setAdditionalProfiles("other")
this
.
environment
.
setActiveProfiles
(
"other"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
String
property
=
this
.
environment
.
getProperty
(
"my.property"
);
// The "other" profile is activated in SpringApplication so it should take
// precedence over the default profile
assertThat
(
property
,
equalTo
(
"fromotherpropertiesfile"
));
}
@Test
public
void
loadPropertiesThenProfilePropertiesActivatedInFirst
()
throws
Exception
{
this
.
initializer
.
setSearchNames
(
"enableprofile"
);
this
.
initializer
.
setSearchNames
(
"enableprofile"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
String
property
=
this
.
environment
.
getProperty
(
"my.property"
);
String
property
=
this
.
environment
.
getProperty
(
"my.property"
);
...
...
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