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
abdc2390
Commit
abdc2390
authored
May 03, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop ignoreNestedProperties attribute from @ConfigurationProperties
Closes gh-8657
parent
12dda513
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
89 deletions
+3
-89
ConfigurationProperties.java
...work/boot/context/properties/ConfigurationProperties.java
+0
-7
ConfigurationPropertiesBindingPostProcessor.java
...operties/ConfigurationPropertiesBindingPostProcessor.java
+1
-8
NoUnboundElementsBindHandler.java
...properties/bind/handler/NoUnboundElementsBindHandler.java
+2
-20
EnableConfigurationPropertiesTests.java
...ontext/properties/EnableConfigurationPropertiesTests.java
+0
-23
NoUnboundElementsBindHandlerTests.java
...rties/bind/handler/NoUnboundElementsBindHandlerTests.java
+0
-31
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java
View file @
abdc2390
...
@@ -65,13 +65,6 @@ public @interface ConfigurationProperties {
...
@@ -65,13 +65,6 @@ public @interface ConfigurationProperties {
*/
*/
boolean
ignoreInvalidFields
()
default
false
;
boolean
ignoreInvalidFields
()
default
false
;
/**
* Flag to indicate that when binding to this object fields with periods in their
* names should be ignored.
* @return the flag value (default false)
*/
boolean
ignoreNestedProperties
()
default
false
;
/**
/**
* Flag to indicate that when binding to this object unknown fields should be ignored.
* Flag to indicate that when binding to this object unknown fields should be ignored.
* An unknown field could be a sign of a mistake in the Properties.
* An unknown field could be a sign of a mistake in the Properties.
...
...
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java
View file @
abdc2390
...
@@ -38,7 +38,6 @@ import org.springframework.boot.context.properties.bind.Bindable;
...
@@ -38,7 +38,6 @@ import org.springframework.boot.context.properties.bind.Bindable;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver
;
import
org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver
;
import
org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler
;
import
org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler
;
import
org.springframework.boot.context.properties.bind.handler.IgnoreNestedPropertiesBindHandler
;
import
org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler
;
import
org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler
;
import
org.springframework.boot.context.properties.bind.validation.ValidationBindHandler
;
import
org.springframework.boot.context.properties.bind.validation.ValidationBindHandler
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySources
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySources
;
...
@@ -368,8 +367,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
...
@@ -368,8 +367,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
details
.
append
(
"prefix="
).
append
(
annotation
.
prefix
());
details
.
append
(
"prefix="
).
append
(
annotation
.
prefix
());
details
.
append
(
", ignoreInvalidFields="
).
append
(
annotation
.
ignoreInvalidFields
());
details
.
append
(
", ignoreInvalidFields="
).
append
(
annotation
.
ignoreInvalidFields
());
details
.
append
(
", ignoreUnknownFields="
).
append
(
annotation
.
ignoreUnknownFields
());
details
.
append
(
", ignoreUnknownFields="
).
append
(
annotation
.
ignoreUnknownFields
());
details
.
append
(
", ignoreNestedProperties="
)
.
append
(
annotation
.
ignoreNestedProperties
());
return
details
.
toString
();
return
details
.
toString
();
}
}
...
@@ -413,11 +410,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
...
@@ -413,11 +410,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
handler
=
new
IgnoreErrorsBindHandler
(
handler
);
handler
=
new
IgnoreErrorsBindHandler
(
handler
);
}
}
if
(!
annotation
.
ignoreUnknownFields
())
{
if
(!
annotation
.
ignoreUnknownFields
())
{
handler
=
new
NoUnboundElementsBindHandler
(
handler
,
handler
=
new
NoUnboundElementsBindHandler
(
handler
);
annotation
.
ignoreNestedProperties
());
}
if
(
annotation
.
ignoreNestedProperties
())
{
handler
=
new
IgnoreNestedPropertiesBindHandler
(
handler
);
}
}
if
(
validator
!=
null
)
{
if
(
validator
!=
null
)
{
handler
=
new
ValidationBindHandler
(
handler
,
validator
);
handler
=
new
ValidationBindHandler
(
handler
,
validator
);
...
...
spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java
View file @
abdc2390
...
@@ -40,28 +40,14 @@ import org.springframework.boot.context.properties.source.IterableConfigurationP
...
@@ -40,28 +40,14 @@ import org.springframework.boot.context.properties.source.IterableConfigurationP
*/
*/
public
class
NoUnboundElementsBindHandler
extends
AbstractBindHandler
{
public
class
NoUnboundElementsBindHandler
extends
AbstractBindHandler
{
private
final
boolean
ignoreNested
;
private
final
Set
<
ConfigurationPropertyName
>
boundNames
=
new
HashSet
<>();
private
final
Set
<
ConfigurationPropertyName
>
boundNames
=
new
HashSet
<>();
public
NoUnboundElementsBindHandler
()
{
NoUnboundElementsBindHandler
()
{
super
();
this
.
ignoreNested
=
false
;
}
public
NoUnboundElementsBindHandler
(
boolean
ignoreNested
)
{
super
();
super
();
this
.
ignoreNested
=
ignoreNested
;
}
}
public
NoUnboundElementsBindHandler
(
BindHandler
parent
)
{
public
NoUnboundElementsBindHandler
(
BindHandler
parent
)
{
super
(
parent
);
super
(
parent
);
this
.
ignoreNested
=
false
;
}
public
NoUnboundElementsBindHandler
(
BindHandler
parent
,
boolean
ignoreNested
)
{
super
(
parent
);
this
.
ignoreNested
=
ignoreNested
;
}
}
@Override
@Override
...
@@ -110,11 +96,7 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
...
@@ -110,11 +96,7 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
private
boolean
isUnbound
(
ConfigurationPropertyName
name
,
private
boolean
isUnbound
(
ConfigurationPropertyName
name
,
ConfigurationPropertyName
candidate
)
{
ConfigurationPropertyName
candidate
)
{
boolean
isParent
=
candidate
.
getParent
()
!=
null
return
name
.
isAncestorOf
(
candidate
)
&&
!
this
.
boundNames
.
contains
(
candidate
);
&&
name
.
equals
(
candidate
.
getParent
());
boolean
isAncestor
=
name
.
isAncestorOf
(
candidate
);
return
((
this
.
ignoreNested
?
isParent
:
isAncestor
)
&&
!
this
.
boundNames
.
contains
(
candidate
));
}
}
}
}
spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java
View file @
abdc2390
...
@@ -118,18 +118,6 @@ public class EnableConfigurationPropertiesTests {
...
@@ -118,18 +118,6 @@ public class EnableConfigurationPropertiesTests {
assertThat
(
this
.
context
.
getBean
(
TestProperties
.
class
).
name
).
isEqualTo
(
"foo"
);
assertThat
(
this
.
context
.
getBean
(
TestProperties
.
class
).
name
).
isEqualTo
(
"foo"
);
}
}
@Test
public
void
testIgnoreNestedPropertiesBinding
()
{
removeSystemProperties
();
this
.
context
.
register
(
IgnoreNestedTestConfiguration
.
class
);
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"name=foo"
,
"nested.name=bar"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
IgnoreNestedTestProperties
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
TestProperties
.
class
).
name
).
isEqualTo
(
"foo"
);
}
@Test
@Test
public
void
testExceptionOnValidation
()
{
public
void
testExceptionOnValidation
()
{
this
.
context
.
register
(
ExceptionIfInvalidTestConfiguration
.
class
);
this
.
context
.
register
(
ExceptionIfInvalidTestConfiguration
.
class
);
...
@@ -380,12 +368,6 @@ public class EnableConfigurationPropertiesTests {
...
@@ -380,12 +368,6 @@ public class EnableConfigurationPropertiesTests {
}
}
@Configuration
@EnableConfigurationProperties
(
IgnoreNestedTestProperties
.
class
)
protected
static
class
IgnoreNestedTestConfiguration
{
}
@Configuration
@Configuration
@EnableConfigurationProperties
(
ExceptionIfInvalidTestProperties
.
class
)
@EnableConfigurationProperties
(
ExceptionIfInvalidTestProperties
.
class
)
protected
static
class
ExceptionIfInvalidTestConfiguration
{
protected
static
class
ExceptionIfInvalidTestConfiguration
{
...
@@ -616,11 +598,6 @@ public class EnableConfigurationPropertiesTests {
...
@@ -616,11 +598,6 @@ public class EnableConfigurationPropertiesTests {
}
}
@ConfigurationProperties
(
ignoreUnknownFields
=
false
,
ignoreNestedProperties
=
true
)
protected
static
class
IgnoreNestedTestProperties
extends
TestProperties
{
}
@ConfigurationProperties
@ConfigurationProperties
@Validated
@Validated
protected
static
class
ExceptionIfInvalidTestProperties
extends
TestProperties
{
protected
static
class
ExceptionIfInvalidTestProperties
extends
TestProperties
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandlerTests.java
View file @
abdc2390
...
@@ -103,37 +103,6 @@ public class NoUnboundElementsBindHandlerTests {
...
@@ -103,37 +103,6 @@ public class NoUnboundElementsBindHandlerTests {
assertThat
(
bound
.
getFoo
()).
isEqualTo
(
"bar"
);
assertThat
(
bound
.
getFoo
()).
isEqualTo
(
"bar"
);
}
}
@Test
public
void
bindWhenUsingNoUnboundElementsHandlerIgnoreNestedAndUnboundChildShouldThrowException
()
throws
Exception
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"example.foo"
,
"bar"
);
source
.
put
(
"example.baz"
,
"bar"
);
this
.
sources
.
add
(
source
);
this
.
binder
=
new
Binder
(
this
.
sources
);
try
{
this
.
binder
.
bind
(
"example"
,
Bindable
.
of
(
Example
.
class
),
new
NoUnboundElementsBindHandler
(
true
));
fail
(
"did not throw"
);
}
catch
(
BindException
ex
)
{
assertThat
(
ex
.
getCause
().
getMessage
())
.
contains
(
"The elements [example.baz] were left unbound"
);
}
}
@Test
public
void
bindWhenUsingNoUnboundElementsHandlerIgnoreNestedAndUnboundGrandchildShouldBind
()
throws
Exception
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"example.foo"
,
"bar"
);
source
.
put
(
"example.foo.baz"
,
"bar"
);
this
.
sources
.
add
(
source
);
this
.
binder
=
new
Binder
(
this
.
sources
);
this
.
binder
.
bind
(
"example"
,
Bindable
.
of
(
Example
.
class
),
new
NoUnboundElementsBindHandler
(
true
));
}
public
static
class
Example
{
public
static
class
Example
{
private
String
foo
;
private
String
foo
;
...
...
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