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
fce1c3ff
Commit
fce1c3ff
authored
Feb 08, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
1f0672f6
7d247a71
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
3 deletions
+43
-3
PropertySourcesPropertyValues.java
...ingframework/boot/bind/PropertySourcesPropertyValues.java
+15
-2
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+11
-1
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+16
-0
testactiveprofiles.properties
spring-boot/src/test/resources/testactiveprofiles.properties
+1
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java
View file @
fce1c3ff
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -63,8 +63,21 @@ public class PropertySourcesPropertyValues implements PropertyValues {
* @param propertySources a PropertySources instance
*/
public
PropertySourcesPropertyValues
(
PropertySources
propertySources
)
{
this
(
propertySources
,
true
);
}
/**
* Create a new PropertyValues from the given PropertySources that will optionally
* resolve placeholders.
* @param propertySources a PropertySources instance
* @param resolvePlaceholders {@code true} if placeholders should be resolved,
* otherwise {@code false}
* @since 1.5.2
*/
public
PropertySourcesPropertyValues
(
PropertySources
propertySources
,
boolean
resolvePlaceholders
)
{
this
(
propertySources
,
(
Collection
<
String
>)
null
,
PropertyNamePatternsMatcher
.
ALL
,
true
);
resolvePlaceholders
);
}
/**
...
...
spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
fce1c3ff
...
...
@@ -481,10 +481,20 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
SpringProfiles
springProfiles
=
new
SpringProfiles
();
RelaxedDataBinder
dataBinder
=
new
RelaxedDataBinder
(
springProfiles
,
"spring.profiles"
);
dataBinder
.
bind
(
new
PropertySourcesPropertyValues
(
propertySources
));
dataBinder
.
bind
(
new
PropertySourcesPropertyValues
(
propertySources
,
false
));
springProfiles
.
setActive
(
resolvePlaceholders
(
springProfiles
.
getActive
()));
springProfiles
.
setInclude
(
resolvePlaceholders
(
springProfiles
.
getInclude
()));
return
springProfiles
;
}
private
List
<
String
>
resolvePlaceholders
(
List
<
String
>
values
)
{
List
<
String
>
resolved
=
new
ArrayList
<
String
>();
for
(
String
value
:
values
)
{
resolved
.
add
(
this
.
environment
.
resolvePlaceholders
(
value
));
}
return
resolved
;
}
private
void
maybeActivateProfiles
(
Set
<
Profile
>
profiles
)
{
if
(
this
.
activatedProfiles
)
{
if
(!
profiles
.
isEmpty
())
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
fce1c3ff
...
...
@@ -23,7 +23,9 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
ch.qos.logback.classic.BasicConfigurator
;
...
...
@@ -804,6 +806,20 @@ public class ConfigFileApplicationListenerTests {
.
isFalse
();
}
@Test
public
void
activeProfilesCanBeConfiguredUsingPlaceholdersResolvedAgainstTheEnvironment
()
throws
Exception
{
Map
<
String
,
Object
>
source
=
new
HashMap
<
String
,
Object
>();
source
.
put
(
"activeProfile"
,
"testPropertySource"
);
org
.
springframework
.
core
.
env
.
PropertySource
<?>
propertySource
=
new
MapPropertySource
(
"test"
,
source
);
this
.
environment
.
getPropertySources
().
addLast
(
propertySource
);
this
.
initializer
.
setSearchNames
(
"testactiveprofiles"
);
this
.
initializer
.
postProcessEnvironment
(
this
.
environment
,
this
.
application
);
assertThat
(
this
.
environment
.
getActiveProfiles
())
.
containsExactly
(
"testPropertySource"
);
}
private
Condition
<
ConfigurableEnvironment
>
matchingPropertySource
(
final
String
sourceName
)
{
return
new
Condition
<
ConfigurableEnvironment
>(
...
...
spring-boot/src/test/resources/testactiveprofiles.properties
0 → 100644
View file @
fce1c3ff
spring.profiles.active
=
${activeProfile:propertiesfile}
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