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
c41199ba
Commit
c41199ba
authored
Aug 02, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
6c5567af
7e2494eb
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 @
c41199ba
...
...
@@ -332,6 +332,7 @@ public class ConfigFileApplicationListener
addToLoaded
(
MutablePropertySources:
:
addLast
,
false
));
this
.
processedProfiles
.
add
(
profile
);
}
resetEnvironmentProfiles
(
this
.
processedProfiles
);
load
(
null
,
this
::
getNegativeProfileFilter
,
addToLoaded
(
MutablePropertySources:
:
addFirst
,
true
));
addLoadedPropertySources
();
...
...
@@ -669,6 +670,21 @@ public class ConfigFileApplicationListener
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
()
{
MutablePropertySources
destination
=
this
.
environment
.
getPropertySources
();
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 @
c41199ba
...
...
@@ -407,7 +407,7 @@ public class ConfigFileApplicationListenerTests {
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
environment
,
"spring.profiles.active=dev"
,
"spring.profiles.include=other"
);
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"
))
.
isEqualTo
(
"fromdevpropertiesfile"
);
validateProfilePrecedence
(
null
,
"other"
,
"dev"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerYamlProfileNegationTests.java
View file @
c41199ba
...
...
@@ -116,6 +116,20 @@ public class ConfigFileApplicationListenerYamlProfileNegationTests {
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
public
void
yamlProfileCascadingOverrideProfilesB
()
{
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