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
0d75995a
Commit
0d75995a
authored
Aug 25, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish JSR-303 detection
parent
a08aac6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
19 deletions
+31
-19
ConfigurationPropertiesBindingPostProcessor.java
...operties/ConfigurationPropertiesBindingPostProcessor.java
+31
-19
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java
View file @
0d75995a
...
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
context
.
properties
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
...
...
@@ -62,12 +61,13 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
* @author Phillip Webb
*/
public
class
ConfigurationPropertiesBindingPostProcessor
implements
BeanPostProcessor
,
BeanFactoryAware
,
ResourceLoaderAware
,
EnvironmentAware
,
BeanClassLoader
Aware
,
ApplicationContextAware
,
InitializingBean
,
DisposableBean
{
BeanFactoryAware
,
ResourceLoaderAware
,
EnvironmentAware
,
ApplicationContext
Aware
,
InitializingBean
,
DisposableBean
{
public
static
final
String
VALIDATOR_BEAN_NAME
=
"configurationPropertiesValidator"
;
private
static
final
String
VALIDATOR_CLASS
=
"javax.validation.Validator"
;
private
static
final
String
[]
VALIDATOR_CLASSES
=
{
"javax.validation.Validator"
,
"javax.validation.ValidatorFactory"
};
private
PropertySources
propertySources
;
...
...
@@ -87,8 +87,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
private
Environment
environment
=
new
StandardEnvironment
();
private
ClassLoader
beanClassLoader
;
private
ApplicationContext
applicationContext
;
/**
...
...
@@ -127,11 +125,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
this
.
environment
=
environment
;
}
@Override
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
this
.
beanClassLoader
=
classLoader
;
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
...
...
@@ -146,14 +139,9 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
if
(
this
.
validator
==
null
)
{
this
.
validator
=
getOptionalBean
(
VALIDATOR_BEAN_NAME
,
Validator
.
class
);
if
(
this
.
validator
==
null
&&
ClassUtils
.
isPresent
(
VALIDATOR_CLASS
,
this
.
beanClassLoader
))
{
LocalValidatorFactoryBean
validatorToUse
=
(
LocalValidatorFactoryBean
)
ClassUtils
.
forName
(
LocalValidatorFactoryBean
.
class
.
getName
(),
this
.
beanClassLoader
).
newInstance
();
validatorToUse
.
setApplicationContext
(
this
.
applicationContext
);
validatorToUse
.
afterPropertiesSet
();
this
.
validator
=
validatorToUse
;
if
(
this
.
validator
==
null
&&
isJsr303Present
())
{
this
.
validator
=
new
Jsr303ValidatorFactory
()
.
run
(
this
.
applicationContext
);
this
.
ownedValidator
=
true
;
}
}
...
...
@@ -165,6 +153,15 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
}
}
private
boolean
isJsr303Present
()
{
for
(
String
validatorClass
:
VALIDATOR_CLASSES
)
{
if
(!
ClassUtils
.
isPresent
(
validatorClass
,
null
))
{
return
false
;
}
}
return
true
;
}
@Override
public
void
destroy
()
throws
Exception
{
if
(
this
.
ownedValidator
)
{
...
...
@@ -331,4 +328,19 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
return
this
.
defaultConversionService
;
}
/**
* Factory to create JSR 303 LocalValidatorFactoryBean. Inner class to prevent class
* loader issues.
*/
private
static
class
Jsr303ValidatorFactory
{
public
Validator
run
(
ApplicationContext
applicationContext
)
{
LocalValidatorFactoryBean
validator
=
new
LocalValidatorFactoryBean
();
validator
.
setApplicationContext
(
applicationContext
);
validator
.
afterPropertiesSet
();
return
validator
;
}
}
}
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