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
300e570f
Commit
300e570f
authored
Jul 21, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverse priority of property sources when extracting sub properties
Fixes gh-1259
parent
a9b8563b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
PropertySourceUtils.java
...va/org/springframework/boot/bind/PropertySourceUtils.java
+1
-1
RelaxedPropertyResolverTests.java
...ringframework/boot/bind/RelaxedPropertyResolverTests.java
+34
-4
No files found.
spring-boot/src/main/java/org/springframework/boot/bind/PropertySourceUtils.java
View file @
300e570f
...
@@ -67,7 +67,7 @@ public abstract class PropertySourceUtils {
...
@@ -67,7 +67,7 @@ public abstract class PropertySourceUtils {
.
getPropertyNames
())
{
.
getPropertyNames
())
{
String
key
=
PropertySourceUtils
.
getSubKey
(
name
,
rootPrefix
,
String
key
=
PropertySourceUtils
.
getSubKey
(
name
,
rootPrefix
,
keyPrefixes
);
keyPrefixes
);
if
(
key
!=
null
)
{
if
(
key
!=
null
&&
!
subProperties
.
containsKey
(
key
)
)
{
subProperties
.
put
(
key
,
source
.
getProperty
(
name
));
subProperties
.
put
(
key
,
source
.
getProperty
(
name
));
}
}
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java
View file @
300e570f
...
@@ -16,20 +16,24 @@
...
@@ -16,20 +16,24 @@
package
org
.
springframework
.
boot
.
bind
;
package
org
.
springframework
.
boot
.
bind
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertiesPropertySource
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
/**
* Tests for {@link RelaxedPropertyResolver}.
* Tests for {@link RelaxedPropertyResolver}.
*
*
...
@@ -173,4 +177,30 @@ public class RelaxedPropertyResolverTests {
...
@@ -173,4 +177,30 @@ public class RelaxedPropertyResolverTests {
assertThat
(
subProperties
.
get
(
"a.c"
),
equalTo
((
Object
)
"2"
));
assertThat
(
subProperties
.
get
(
"a.c"
),
equalTo
((
Object
)
"2"
));
assertThat
(
subProperties
.
get
(
"a.d"
),
equalTo
((
Object
)
"3"
));
assertThat
(
subProperties
.
get
(
"a.d"
),
equalTo
((
Object
)
"3"
));
}
}
@Test
public
void
testPropertySource
()
throws
Exception
{
Properties
properties
;
PropertiesPropertySource
propertySource
;
String
propertyPrefix
=
"spring.datasource."
;
String
propertyName
=
"password"
;
String
fullPropertyName
=
propertyPrefix
+
propertyName
;
StandardEnvironment
environment
=
new
StandardEnvironment
();
MutablePropertySources
sources
=
environment
.
getPropertySources
();
properties
=
new
Properties
();
properties
.
put
(
fullPropertyName
,
"systemPassword"
);
propertySource
=
new
PropertiesPropertySource
(
"system"
,
properties
);
sources
.
addLast
(
propertySource
);
properties
=
new
Properties
();
properties
.
put
(
fullPropertyName
,
"propertiesPassword"
);
propertySource
=
new
PropertiesPropertySource
(
"properties"
,
properties
);
sources
.
addLast
(
propertySource
);
RelaxedPropertyResolver
propertyResolver
=
new
RelaxedPropertyResolver
(
environment
,
propertyPrefix
);
String
directProperty
=
propertyResolver
.
getProperty
(
propertyName
);
Map
<
String
,
Object
>
subProperties
=
propertyResolver
.
getSubProperties
(
""
);
String
subProperty
=
(
String
)
subProperties
.
get
(
propertyName
);
assertEquals
(
directProperty
,
subProperty
);
}
}
}
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