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
7e2494eb
Commit
7e2494eb
authored
Aug 01, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set environment active profiles according to processing order
Fixes gh-13965
parent
e4442f4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+16
-0
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+1
-1
ConfigFileApplicationListenerYamlProfileNegationTests.java
...onfigFileApplicationListenerYamlProfileNegationTests.java
+14
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
7e2494eb
...
@@ -337,6 +337,7 @@ public class ConfigFileApplicationListener
...
@@ -337,6 +337,7 @@ public class ConfigFileApplicationListener
addToLoaded
(
MutablePropertySources:
:
addLast
,
false
));
addToLoaded
(
MutablePropertySources:
:
addLast
,
false
));
this
.
processedProfiles
.
add
(
profile
);
this
.
processedProfiles
.
add
(
profile
);
}
}
resetEnvironmentProfiles
(
this
.
processedProfiles
);
load
(
null
,
this
::
getNegativeProfileFilter
,
load
(
null
,
this
::
getNegativeProfileFilter
,
addToLoaded
(
MutablePropertySources:
:
addFirst
,
true
));
addToLoaded
(
MutablePropertySources:
:
addFirst
,
true
));
addLoadedPropertySources
();
addLoadedPropertySources
();
...
@@ -673,6 +674,21 @@ public class ConfigFileApplicationListener
...
@@ -673,6 +674,21 @@ public class ConfigFileApplicationListener
return
new
LinkedHashSet
<>(
list
);
return
new
LinkedHashSet
<>(
list
);
}
}
/**
* This ensures that the order of active profiles in the {@link Environment}
* matches the order in which the profiles were processed.
* @param processedProfiles the processed profiles
*/
private
void
resetEnvironmentProfiles
(
List
<
Profile
>
processedProfiles
)
{
String
[]
names
=
processedProfiles
.
stream
().
filter
((
profile
)
->
{
if
(
profile
!=
null
&&
!
profile
.
isDefaultProfile
())
{
return
true
;
}
return
false
;
}).
map
(
Profile:
:
getName
).
toArray
(
String
[]::
new
);
this
.
environment
.
setActiveProfiles
(
names
);
}
private
void
addLoadedPropertySources
()
{
private
void
addLoadedPropertySources
()
{
MutablePropertySources
destination
=
this
.
environment
.
getPropertySources
();
MutablePropertySources
destination
=
this
.
environment
.
getPropertySources
();
List
<
MutablePropertySources
>
loaded
=
new
ArrayList
<>(
this
.
loaded
.
values
());
List
<
MutablePropertySources
>
loaded
=
new
ArrayList
<>(
this
.
loaded
.
values
());
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
7e2494eb
...
@@ -406,7 +406,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -406,7 +406,7 @@ public class ConfigFileApplicationListenerTests {
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
environment
,
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
environment
,
"spring.profiles.active=dev"
,
"spring.profiles.include=other"
);
"spring.profiles.active=dev"
,
"spring.profiles.include=other"
);
this
.
initializer
.
postProcessEnvironment
(
this
.
environment
,
this
.
application
);
this
.
initializer
.
postProcessEnvironment
(
this
.
environment
,
this
.
application
);
assertThat
(
this
.
environment
.
getActiveProfiles
()).
contains
(
"dev"
,
"other
"
);
assertThat
(
this
.
environment
.
getActiveProfiles
()).
contains
Exactly
(
"other"
,
"dev
"
);
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
))
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
))
.
isEqualTo
(
"fromdevpropertiesfile"
);
.
isEqualTo
(
"fromdevpropertiesfile"
);
validateProfilePrecedence
(
null
,
"other"
,
"dev"
);
validateProfilePrecedence
(
null
,
"other"
,
"dev"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerYamlProfileNegationTests.java
View file @
7e2494eb
...
@@ -116,6 +116,20 @@ public class ConfigFileApplicationListenerYamlProfileNegationTests {
...
@@ -116,6 +116,20 @@ public class ConfigFileApplicationListenerYamlProfileNegationTests {
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-e"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-e"
)).
isNull
();
}
}
@Test
public
void
yamlProfileCascadingMultipleActiveProfilesViaPropertiesShouldPreserveOrder
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=cascadingprofiles"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=A,B"
);
assertVersionProperty
(
this
.
context
,
"D"
,
"A"
,
"C"
,
"E"
,
"B"
,
"D"
);
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-a"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-b"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-c"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-d"
)).
isNull
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"not-e"
)).
isNull
();
}
@Test
@Test
public
void
yamlProfileCascadingOverrideProfilesB
()
{
public
void
yamlProfileCascadingOverrideProfilesB
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
...
...
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