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
1efac099
Commit
1efac099
authored
Jul 27, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x'
Closes gh-22586
parents
d16838e4
8ff2b9f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
NoUnboundElementsBindHandler.java
...properties/bind/handler/NoUnboundElementsBindHandler.java
+9
-0
ConfigurationPropertiesTests.java
...boot/context/properties/ConfigurationPropertiesTests.java
+19
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java
View file @
1efac099
...
@@ -72,6 +72,15 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
...
@@ -72,6 +72,15 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
return
super
.
onSuccess
(
name
,
target
,
context
,
result
);
return
super
.
onSuccess
(
name
,
target
,
context
,
result
);
}
}
@Override
public
Object
onFailure
(
ConfigurationPropertyName
name
,
Bindable
<?>
target
,
BindContext
context
,
Exception
error
)
throws
Exception
{
if
(
error
instanceof
UnboundConfigurationPropertiesException
)
{
throw
error
;
}
return
super
.
onFailure
(
name
,
target
,
context
,
error
);
}
@Override
@Override
public
void
onFinish
(
ConfigurationPropertyName
name
,
Bindable
<?>
target
,
BindContext
context
,
Object
result
)
public
void
onFinish
(
ConfigurationPropertyName
name
,
Bindable
<?>
target
,
BindContext
context
,
Object
result
)
throws
Exception
{
throws
Exception
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java
View file @
1efac099
...
@@ -175,6 +175,14 @@ class ConfigurationPropertiesTests {
...
@@ -175,6 +175,14 @@ class ConfigurationPropertiesTests {
.
withCauseInstanceOf
(
BindException
.
class
);
.
withCauseInstanceOf
(
BindException
.
class
);
}
}
@Test
void
givenIgnoreUnknownFieldsFalseAndIgnoreInvalidFieldsTrueWhenThereAreUnknownFieldsThenBindingShouldFail
()
{
removeSystemProperties
();
assertThatExceptionOfType
(
ConfigurationPropertiesBindException
.
class
).
isThrownBy
(
()
->
load
(
IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueConfiguration
.
class
,
"name=foo"
,
"bar=baz"
))
.
withCauseInstanceOf
(
BindException
.
class
);
}
@Test
@Test
void
loadWhenHasIgnoreInvalidFieldsTrueAndInvalidFieldsShouldBind
()
{
void
loadWhenHasIgnoreInvalidFieldsTrueAndInvalidFieldsShouldBind
()
{
load
(
IgnoreInvalidFieldsFalseProperties
.
class
,
"com.example.bar=spam"
);
load
(
IgnoreInvalidFieldsFalseProperties
.
class
,
"com.example.bar=spam"
);
...
@@ -1000,6 +1008,12 @@ class ConfigurationPropertiesTests {
...
@@ -1000,6 +1008,12 @@ class ConfigurationPropertiesTests {
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@EnableConfigurationProperties
(
IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueProperties
.
class
)
static
class
IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueConfiguration
{
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
@EnableConfigurationProperties
(
PrefixProperties
.
class
)
@EnableConfigurationProperties
(
PrefixProperties
.
class
)
static
class
PrefixConfiguration
{
static
class
PrefixConfiguration
{
...
@@ -1447,6 +1461,11 @@ class ConfigurationPropertiesTests {
...
@@ -1447,6 +1461,11 @@ class ConfigurationPropertiesTests {
}
}
@ConfigurationProperties
(
ignoreUnknownFields
=
false
,
ignoreInvalidFields
=
true
)
static
class
IgnoreUnknownFieldsFalseIgnoreInvalidFieldsTrueProperties
extends
BasicProperties
{
}
@EnableConfigurationProperties
@EnableConfigurationProperties
@ConfigurationProperties
(
prefix
=
"com.example"
,
ignoreInvalidFields
=
true
)
@ConfigurationProperties
(
prefix
=
"com.example"
,
ignoreInvalidFields
=
true
)
static
class
IgnoreInvalidFieldsFalseProperties
{
static
class
IgnoreInvalidFieldsFalseProperties
{
...
...
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