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
d47e7ebb
Commit
d47e7ebb
authored
Jun 04, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
a12baed5
e1d21e52
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
12 deletions
+38
-12
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+21
-12
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+11
-0
applicationmultiprofiles.yml
...ring-boot/src/test/resources/applicationmultiprofiles.yml
+6
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
d47e7ebb
...
...
@@ -22,6 +22,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Deque
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedList
;
...
...
@@ -656,27 +657,35 @@ public class ConfigFileApplicationListener
private
void
addLoadedPropertySources
()
{
MutablePropertySources
destination
=
this
.
environment
.
getPropertySources
();
String
lastAdded
=
null
;
List
<
MutablePropertySources
>
loaded
=
new
ArrayList
<>(
this
.
loaded
.
values
());
Collections
.
reverse
(
loaded
);
String
lastAdded
=
null
;
Set
<
String
>
added
=
new
HashSet
<>();
for
(
MutablePropertySources
sources
:
loaded
)
{
for
(
PropertySource
<?>
source
:
sources
)
{
if
(
lastAdded
==
null
)
{
if
(
destination
.
contains
(
DEFAULT_PROPERTIES
))
{
destination
.
addBefore
(
DEFAULT_PROPERTIES
,
source
);
}
else
{
destination
.
addLast
(
source
);
}
}
else
{
destination
.
addAfter
(
lastAdded
,
source
);
if
(
added
.
add
(
source
.
getName
()))
{
addLoadedPropertySource
(
destination
,
lastAdded
,
source
);
lastAdded
=
source
.
getName
();
}
lastAdded
=
source
.
getName
();
}
}
}
private
void
addLoadedPropertySource
(
MutablePropertySources
destination
,
String
lastAdded
,
PropertySource
<?>
source
)
{
if
(
lastAdded
==
null
)
{
if
(
destination
.
contains
(
DEFAULT_PROPERTIES
))
{
destination
.
addBefore
(
DEFAULT_PROPERTIES
,
source
);
}
else
{
destination
.
addLast
(
source
);
}
}
else
{
destination
.
addAfter
(
lastAdded
,
source
);
}
}
}
/**
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
d47e7ebb
...
...
@@ -900,7 +900,18 @@ public class ConfigFileApplicationListenerTests {
this
.
context
=
application
.
run
(
"--spring.config.name=applicationloop"
);
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
assertThat
(
environment
.
acceptsProfiles
(
"loop"
)).
isTrue
();
}
@Test
public
void
multiValueSpringProfiles
()
{
// gh-13362
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.config.name=applicationmultiprofiles"
);
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
assertThat
(
environment
.
acceptsProfiles
(
"test"
)).
isTrue
();
assertThat
(
environment
.
acceptsProfiles
(
"another-test"
)).
isTrue
();
assertThat
(
environment
.
getProperty
(
"message"
)).
isEqualTo
(
"multiprofile"
);
}
private
Condition
<
ConfigurableEnvironment
>
matchingPropertySource
(
...
...
spring-boot-project/spring-boot/src/test/resources/applicationmultiprofiles.yml
0 → 100644
View file @
d47e7ebb
spring.profiles.active
:
test, another-test
message
:
default
---
spring
:
profiles
:
test,another-test
message
:
multiprofile
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