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
29cb21c3
Commit
29cb21c3
authored
May 30, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be lenient with prefix and add period if missing
parent
35414950
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
OnPropertyCondition.java
...ork/boot/autoconfigure/condition/OnPropertyCondition.java
+5
-2
ConditionalOnPropertyTests.java
...t/autoconfigure/condition/ConditionalOnPropertyTests.java
+21
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java
View file @
29cb21c3
...
@@ -40,8 +40,11 @@ class OnPropertyCondition extends SpringBootCondition {
...
@@ -40,8 +40,11 @@ class OnPropertyCondition extends SpringBootCondition {
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
AnnotatedTypeMetadata
metadata
)
{
String
prefix
=
(
String
)
metadata
.
getAnnotationAttributes
(
String
prefix
=
((
String
)
metadata
.
getAnnotationAttributes
(
ConditionalOnProperty
.
class
.
getName
()).
get
(
"prefix"
);
ConditionalOnProperty
.
class
.
getName
()).
get
(
"prefix"
)).
trim
();
if
(!
""
.
equals
(
prefix
)
&&
!
prefix
.
endsWith
(
"."
))
{
prefix
=
prefix
+
"."
;
}
String
[]
names
=
(
String
[])
metadata
.
getAnnotationAttributes
(
String
[]
names
=
(
String
[])
metadata
.
getAnnotationAttributes
(
ConditionalOnProperty
.
class
.
getName
()).
get
(
"value"
);
ConditionalOnProperty
.
class
.
getName
()).
get
(
"value"
);
Boolean
relaxedNames
=
(
Boolean
)
metadata
.
getAnnotationAttributes
(
Boolean
relaxedNames
=
(
Boolean
)
metadata
.
getAnnotationAttributes
(
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java
View file @
29cb21c3
...
@@ -79,6 +79,16 @@ public class ConditionalOnPropertyTests {
...
@@ -79,6 +79,16 @@ public class ConditionalOnPropertyTests {
assertTrue
(
this
.
context
.
containsBean
(
"foo"
));
assertTrue
(
this
.
context
.
containsBean
(
"foo"
));
}
}
@Test
public
void
prefixWithoutPeriod
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
.
getEnvironment
(),
"spring.property=value1"
);
this
.
context
.
register
(
RelaxedPropertiesRequiredConfigurationWithShortPrefix
.
class
);
this
.
context
.
refresh
();
assertTrue
(
this
.
context
.
containsBean
(
"foo"
));
}
@Test
@Test
public
void
nonRelaxedName
()
throws
Exception
{
public
void
nonRelaxedName
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
.
getEnvironment
(),
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
.
getEnvironment
(),
...
@@ -110,6 +120,17 @@ public class ConditionalOnPropertyTests {
...
@@ -110,6 +120,17 @@ public class ConditionalOnPropertyTests {
}
}
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring"
,
value
=
"property"
)
protected
static
class
RelaxedPropertiesRequiredConfigurationWithShortPrefix
{
@Bean
public
String
foo
()
{
return
"foo"
;
}
}
@Configuration
@Configuration
@ConditionalOnProperty
(
value
=
"the-relaxed-property"
,
relaxedNames
=
false
)
@ConditionalOnProperty
(
value
=
"the-relaxed-property"
,
relaxedNames
=
false
)
protected
static
class
NonRelaxedPropertiesRequiredConfiguration
{
protected
static
class
NonRelaxedPropertiesRequiredConfiguration
{
...
...
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