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
0c98d0e7
Commit
0c98d0e7
authored
Apr 05, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow validation api without implementation"
Closes gh-12669
parent
a74dc74e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
17 deletions
+23
-17
ConfigurationPropertiesBinder.java
...oot/context/properties/ConfigurationPropertiesBinder.java
+15
-8
ConfigurationPropertiesJsr303Validator.java
...xt/properties/ConfigurationPropertiesJsr303Validator.java
+4
-6
ValidationExceptionFailureAnalyzerTests.java
...ics/analyzer/ValidationExceptionFailureAnalyzerTests.java
+4
-3
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java
View file @
0c98d0e7
...
@@ -55,7 +55,9 @@ class ConfigurationPropertiesBinder {
...
@@ -55,7 +55,9 @@ class ConfigurationPropertiesBinder {
private
final
Validator
configurationPropertiesValidator
;
private
final
Validator
configurationPropertiesValidator
;
private
Validator
jsr303Validator
;
private
final
boolean
jsr303Present
;
private
volatile
Validator
jsr303Validator
;
private
volatile
Binder
binder
;
private
volatile
Binder
binder
;
...
@@ -66,7 +68,8 @@ class ConfigurationPropertiesBinder {
...
@@ -66,7 +68,8 @@ class ConfigurationPropertiesBinder {
.
getPropertySources
();
.
getPropertySources
();
this
.
configurationPropertiesValidator
=
getConfigurationPropertiesValidator
(
this
.
configurationPropertiesValidator
=
getConfigurationPropertiesValidator
(
applicationContext
,
validatorBeanName
);
applicationContext
,
validatorBeanName
);
this
.
jsr303Present
=
ConfigurationPropertiesJsr303Validator
.
isJsr303Present
(
applicationContext
);
}
}
public
void
bind
(
Bindable
<?>
target
)
{
public
void
bind
(
Bindable
<?>
target
)
{
...
@@ -92,12 +95,8 @@ class ConfigurationPropertiesBinder {
...
@@ -92,12 +95,8 @@ class ConfigurationPropertiesBinder {
if
(
this
.
configurationPropertiesValidator
!=
null
)
{
if
(
this
.
configurationPropertiesValidator
!=
null
)
{
validators
.
add
(
this
.
configurationPropertiesValidator
);
validators
.
add
(
this
.
configurationPropertiesValidator
);
}
}
if
(
this
.
jsr303Present
&&
target
.
getAnnotation
(
Validated
.
class
)
!=
null
)
{
if
(
target
.
getAnnotation
(
Validated
.
class
)
!=
null
)
{
validators
.
add
(
getJsr303Validator
());
this
.
jsr303Validator
=
ConfigurationPropertiesJsr303Validator
.
getIfJsr303Present
(
this
.
applicationContext
);
if
(
this
.
jsr303Validator
!=
null
)
{
validators
.
add
(
this
.
jsr303Validator
);
}
}
}
if
(
target
.
getValue
()
!=
null
&&
target
.
getValue
().
get
()
instanceof
Validator
)
{
if
(
target
.
getValue
()
!=
null
&&
target
.
getValue
().
get
()
instanceof
Validator
)
{
validators
.
add
((
Validator
)
target
.
getValue
().
get
());
validators
.
add
((
Validator
)
target
.
getValue
().
get
());
...
@@ -105,6 +104,14 @@ class ConfigurationPropertiesBinder {
...
@@ -105,6 +104,14 @@ class ConfigurationPropertiesBinder {
return
validators
;
return
validators
;
}
}
private
Validator
getJsr303Validator
()
{
if
(
this
.
jsr303Validator
==
null
)
{
this
.
jsr303Validator
=
new
ConfigurationPropertiesJsr303Validator
(
this
.
applicationContext
);
}
return
this
.
jsr303Validator
;
}
private
BindHandler
getBindHandler
(
ConfigurationProperties
annotation
,
private
BindHandler
getBindHandler
(
ConfigurationProperties
annotation
,
List
<
Validator
>
validators
)
{
List
<
Validator
>
validators
)
{
BindHandler
handler
=
new
IgnoreTopLevelConverterNotFoundBindHandler
();
BindHandler
handler
=
new
IgnoreTopLevelConverterNotFoundBindHandler
();
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesJsr303Validator.java
View file @
0c98d0e7
...
@@ -38,8 +38,7 @@ final class ConfigurationPropertiesJsr303Validator implements Validator {
...
@@ -38,8 +38,7 @@ final class ConfigurationPropertiesJsr303Validator implements Validator {
private
final
Delegate
delegate
;
private
final
Delegate
delegate
;
private
ConfigurationPropertiesJsr303Validator
(
ConfigurationPropertiesJsr303Validator
(
ApplicationContext
applicationContext
)
{
ApplicationContext
applicationContext
)
{
this
.
delegate
=
new
Delegate
(
applicationContext
);
this
.
delegate
=
new
Delegate
(
applicationContext
);
}
}
...
@@ -53,15 +52,14 @@ final class ConfigurationPropertiesJsr303Validator implements Validator {
...
@@ -53,15 +52,14 @@ final class ConfigurationPropertiesJsr303Validator implements Validator {
this
.
delegate
.
validate
(
target
,
errors
);
this
.
delegate
.
validate
(
target
,
errors
);
}
}
public
static
ConfigurationPropertiesJsr303Validator
getIfJsr303Present
(
public
static
boolean
isJsr303Present
(
ApplicationContext
applicationContext
)
{
ApplicationContext
applicationContext
)
{
ClassLoader
classLoader
=
applicationContext
.
getClassLoader
();
ClassLoader
classLoader
=
applicationContext
.
getClassLoader
();
for
(
String
validatorClass
:
VALIDATOR_CLASSES
)
{
for
(
String
validatorClass
:
VALIDATOR_CLASSES
)
{
if
(!
ClassUtils
.
isPresent
(
validatorClass
,
classLoader
))
{
if
(!
ClassUtils
.
isPresent
(
validatorClass
,
classLoader
))
{
return
null
;
return
false
;
}
}
}
}
return
new
ConfigurationPropertiesJsr303Validator
(
applicationContext
)
;
return
true
;
}
}
private
static
class
Delegate
extends
LocalValidatorFactoryBean
{
private
static
class
Delegate
extends
LocalValidatorFactoryBean
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/ValidationExceptionFailureAnalyzerTests.java
View file @
0c98d0e7
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -54,7 +54,8 @@ public class ValidationExceptionFailureAnalyzerTests {
...
@@ -54,7 +54,8 @@ public class ValidationExceptionFailureAnalyzerTests {
@Test
@Test
public
void
nonValidatedPropertiesTest
()
{
public
void
nonValidatedPropertiesTest
()
{
new
AnnotationConfigApplicationContext
(
NonValidatedTestConfiguration
.
class
).
close
();
new
AnnotationConfigApplicationContext
(
NonValidatedTestConfiguration
.
class
)
.
close
();
}
}
@EnableConfigurationProperties
(
TestProperties
.
class
)
@EnableConfigurationProperties
(
TestProperties
.
class
)
...
@@ -71,7 +72,6 @@ public class ValidationExceptionFailureAnalyzerTests {
...
@@ -71,7 +72,6 @@ public class ValidationExceptionFailureAnalyzerTests {
}
}
@EnableConfigurationProperties
(
NonValidatedTestProperties
.
class
)
@EnableConfigurationProperties
(
NonValidatedTestProperties
.
class
)
static
class
NonValidatedTestConfiguration
{
static
class
NonValidatedTestConfiguration
{
...
@@ -84,4 +84,5 @@ public class ValidationExceptionFailureAnalyzerTests {
...
@@ -84,4 +84,5 @@ public class ValidationExceptionFailureAnalyzerTests {
private
static
class
NonValidatedTestProperties
{
private
static
class
NonValidatedTestProperties
{
}
}
}
}
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