Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
10d5926b
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
10d5926b
编写于
11月 29, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Direct use of Bean Definition 1.1 ExecutableValidator
Issue: SPR-13481
上级
f065589a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
30 deletion
+8
-30
spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java
...alidation/beanvalidation/MethodValidationInterceptor.java
+8
-30
未找到文件。
spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java
浏览文件 @
10d5926b
...
@@ -23,6 +23,7 @@ import javax.validation.ConstraintViolationException;
...
@@ -23,6 +23,7 @@ import javax.validation.ConstraintViolationException;
import
javax.validation.Validation
;
import
javax.validation.Validation
;
import
javax.validation.Validator
;
import
javax.validation.Validator
;
import
javax.validation.ValidatorFactory
;
import
javax.validation.ValidatorFactory
;
import
javax.validation.executable.ExecutableValidator
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.aopalliance.intercept.MethodInvocation
;
...
@@ -30,7 +31,6 @@ import org.aopalliance.intercept.MethodInvocation;
...
@@ -30,7 +31,6 @@ import org.aopalliance.intercept.MethodInvocation;
import
org.springframework.core.BridgeMethodResolver
;
import
org.springframework.core.BridgeMethodResolver
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
/**
/**
...
@@ -58,27 +58,6 @@ import org.springframework.validation.annotation.Validated;
...
@@ -58,27 +58,6 @@ import org.springframework.validation.annotation.Validated;
*/
*/
public
class
MethodValidationInterceptor
implements
MethodInterceptor
{
public
class
MethodValidationInterceptor
implements
MethodInterceptor
{
private
static
Method
forExecutablesMethod
;
private
static
Method
validateParametersMethod
;
private
static
Method
validateReturnValueMethod
;
static
{
try
{
forExecutablesMethod
=
Validator
.
class
.
getMethod
(
"forExecutables"
);
Class
<?>
executableValidatorClass
=
forExecutablesMethod
.
getReturnType
();
validateParametersMethod
=
executableValidatorClass
.
getMethod
(
"validateParameters"
,
Object
.
class
,
Method
.
class
,
Object
[].
class
,
Class
[].
class
);
validateReturnValueMethod
=
executableValidatorClass
.
getMethod
(
"validateReturnValue"
,
Object
.
class
,
Method
.
class
,
Object
.
class
,
Class
[].
class
);
}
catch
(
Exception
ex
)
{
// Bean Validation 1.1 ExecutableValidator API not available
}
}
private
final
Validator
validator
;
private
final
Validator
validator
;
...
@@ -112,21 +91,21 @@ public class MethodValidationInterceptor implements MethodInterceptor {
...
@@ -112,21 +91,21 @@ public class MethodValidationInterceptor implements MethodInterceptor {
Class
<?>[]
groups
=
determineValidationGroups
(
invocation
);
Class
<?>[]
groups
=
determineValidationGroups
(
invocation
);
// Standard Bean Validation 1.1 API
// Standard Bean Validation 1.1 API
Object
execVal
=
ReflectionUtils
.
invokeMethod
(
forExecutablesMethod
,
this
.
validator
);
ExecutableValidator
execVal
=
this
.
validator
.
forExecutables
(
);
Method
methodToValidate
=
invocation
.
getMethod
();
Method
methodToValidate
=
invocation
.
getMethod
();
Set
<
ConstraintViolation
<
?
>>
result
;
Set
<
ConstraintViolation
<
Object
>>
result
;
try
{
try
{
result
=
(
Set
<
ConstraintViolation
<?>>)
ReflectionUtils
.
invokeMethod
(
validateParametersMethod
,
result
=
execVal
.
validateParameters
(
execVal
,
invocation
.
getThis
(),
methodToValidate
,
invocation
.
getArguments
(),
groups
);
invocation
.
getThis
(),
methodToValidate
,
invocation
.
getArguments
(),
groups
);
}
}
catch
(
IllegalArgumentException
ex
)
{
catch
(
IllegalArgumentException
ex
)
{
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
// Let's try to find the bridged method on the implementation class...
// Let's try to find the bridged method on the implementation class...
methodToValidate
=
BridgeMethodResolver
.
findBridgedMethod
(
methodToValidate
=
BridgeMethodResolver
.
findBridgedMethod
(
ClassUtils
.
getMostSpecificMethod
(
invocation
.
getMethod
(),
invocation
.
getThis
().
getClass
()));
ClassUtils
.
getMostSpecificMethod
(
invocation
.
getMethod
(),
invocation
.
getThis
().
getClass
()));
result
=
(
Set
<
ConstraintViolation
<?>>)
ReflectionUtils
.
invokeMethod
(
validateParametersMethod
,
result
=
execVal
.
validateParameters
(
execVal
,
invocation
.
getThis
(),
methodToValidate
,
invocation
.
getArguments
(),
groups
);
invocation
.
getThis
(),
methodToValidate
,
invocation
.
getArguments
(),
groups
);
}
}
if
(!
result
.
isEmpty
())
{
if
(!
result
.
isEmpty
())
{
throw
new
ConstraintViolationException
(
result
);
throw
new
ConstraintViolationException
(
result
);
...
@@ -134,8 +113,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
...
@@ -134,8 +113,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
Object
returnValue
=
invocation
.
proceed
();
Object
returnValue
=
invocation
.
proceed
();
result
=
(
Set
<
ConstraintViolation
<?>>)
ReflectionUtils
.
invokeMethod
(
validateReturnValueMethod
,
result
=
execVal
.
validateReturnValue
(
invocation
.
getThis
(),
methodToValidate
,
returnValue
,
groups
);
execVal
,
invocation
.
getThis
(),
methodToValidate
,
returnValue
,
groups
);
if
(!
result
.
isEmpty
())
{
if
(!
result
.
isEmpty
())
{
throw
new
ConstraintViolationException
(
result
);
throw
new
ConstraintViolationException
(
result
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录