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
3ad43e0d
Commit
3ad43e0d
authored
Dec 08, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve placeholders in @ConfigurationProperties prefix
parent
79aa6e77
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
ConfigurationPropertiesBindingPostProcessor.java
...operties/ConfigurationPropertiesBindingPostProcessor.java
+1
-0
ConfigurationPropertiesBindingPostProcessorTests.java
...ies/ConfigurationPropertiesBindingPostProcessorTests.java
+26
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java
View file @
3ad43e0d
...
@@ -289,6 +289,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
...
@@ -289,6 +289,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
String
targetName
=
(
StringUtils
.
hasLength
(
annotation
.
value
())
?
annotation
String
targetName
=
(
StringUtils
.
hasLength
(
annotation
.
value
())
?
annotation
.
value
()
:
annotation
.
prefix
());
.
value
()
:
annotation
.
prefix
());
if
(
StringUtils
.
hasLength
(
targetName
))
{
if
(
StringUtils
.
hasLength
(
targetName
))
{
targetName
=
this
.
environment
.
resolvePlaceholders
(
targetName
);
factory
.
setTargetName
(
targetName
);
factory
.
setTargetName
(
targetName
);
}
}
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java
View file @
3ad43e0d
...
@@ -148,6 +148,16 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -148,6 +148,16 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
equalTo
(
"foo"
));
equalTo
(
"foo"
));
}
}
@Test
public
void
placeholderInPrefix
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"foo:spam"
,
"spam.foo:bar"
);
this
.
context
.
register
(
PlaceholderPrefixConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
PlaceholderPrefixConfiguration
.
class
).
getFoo
(),
equalTo
(
"bar"
));
}
@Test
@Test
public
void
placeholderResolutionWithCustomLocation
()
throws
Exception
{
public
void
placeholderResolutionWithCustomLocation
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
...
@@ -373,6 +383,22 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -373,6 +383,22 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
}
}
@EnableConfigurationProperties
@ConfigurationProperties
(
prefix
=
"${foo:bar}"
)
public
static
class
PlaceholderPrefixConfiguration
{
private
String
foo
;
public
String
getFoo
()
{
return
this
.
foo
;
}
public
void
setFoo
(
String
foo
)
{
this
.
foo
=
foo
;
}
}
@EnableConfigurationProperties
@EnableConfigurationProperties
@ConfigurationProperties
(
locations
=
"custom-location.yml"
)
@ConfigurationProperties
(
locations
=
"custom-location.yml"
)
public
static
class
CustomConfigurationLocation
{
public
static
class
CustomConfigurationLocation
{
...
...
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