Exclude FactoryBean implementation methods on CGLIB proxies as well
Issue: SPR-17374
This commit is contained in:
parent
fa096dc60f
commit
dc1e3b4628
|
@ -123,7 +123,16 @@ public class MethodValidationTests {
|
||||||
@Test
|
@Test
|
||||||
public void testLazyValidatorForMethodValidation() {
|
public void testLazyValidatorForMethodValidation() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||||
LazyMethodValidationConfig.class, CustomValidatorBean.class, MyValidBean.class, MyValidFactoryBean.class);
|
LazyMethodValidationConfig.class, CustomValidatorBean.class,
|
||||||
|
MyValidBean.class, MyValidFactoryBean.class);
|
||||||
|
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLazyValidatorForMethodValidationWithProxyTargetClass() {
|
||||||
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||||
|
LazyMethodValidationConfigWithProxyTargetClass.class, CustomValidatorBean.class,
|
||||||
|
MyValidBean.class, MyValidFactoryBean.class);
|
||||||
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,4 +227,17 @@ public class MethodValidationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class LazyMethodValidationConfigWithProxyTargetClass {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public static MethodValidationPostProcessor methodValidationPostProcessor(@Lazy Validator validator) {
|
||||||
|
MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
|
||||||
|
postProcessor.setValidator(validator);
|
||||||
|
postProcessor.setProxyTargetClass(true);
|
||||||
|
return postProcessor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,23 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
||||||
|
|
||||||
private boolean isFactoryBeanMetadataMethod(Method method) {
|
private boolean isFactoryBeanMetadataMethod(Method method) {
|
||||||
Class<?> clazz = method.getDeclaringClass();
|
Class<?> clazz = method.getDeclaringClass();
|
||||||
return ((clazz == FactoryBean.class || clazz == SmartFactoryBean.class) &&
|
|
||||||
!method.getName().equals("getObject"));
|
// Call from interface-based proxy handle, allowing for an efficient check?
|
||||||
|
if (clazz.isInterface()) {
|
||||||
|
return ((clazz == FactoryBean.class || clazz == SmartFactoryBean.class) &&
|
||||||
|
!method.getName().equals("getObject"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call from CGLIB proxy handle, potentially implementing a FactoryBean method?
|
||||||
|
Class<?> factoryBeanType = null;
|
||||||
|
if (SmartFactoryBean.class.isAssignableFrom(clazz)) {
|
||||||
|
factoryBeanType = SmartFactoryBean.class;
|
||||||
|
}
|
||||||
|
else if (FactoryBean.class.isAssignableFrom(clazz)) {
|
||||||
|
factoryBeanType = FactoryBean.class;
|
||||||
|
}
|
||||||
|
return (factoryBeanType != null && !method.getName().equals("getObject") &&
|
||||||
|
ClassUtils.hasMethod(factoryBeanType, method.getName(), method.getParameterTypes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -120,7 +120,16 @@ public class MethodValidationTests {
|
||||||
@Test
|
@Test
|
||||||
public void testLazyValidatorForMethodValidation() {
|
public void testLazyValidatorForMethodValidation() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||||
LazyMethodValidationConfig.class, CustomValidatorBean.class, MyValidBean.class, MyValidFactoryBean.class);
|
LazyMethodValidationConfig.class, CustomValidatorBean.class,
|
||||||
|
MyValidBean.class, MyValidFactoryBean.class);
|
||||||
|
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLazyValidatorForMethodValidationWithProxyTargetClass() {
|
||||||
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||||
|
LazyMethodValidationConfigWithProxyTargetClass.class, CustomValidatorBean.class,
|
||||||
|
MyValidBean.class, MyValidFactoryBean.class);
|
||||||
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
ctx.getBeansOfType(MyValidInterface.class).values().forEach(bean -> bean.myValidMethod("value", 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,4 +224,17 @@ public class MethodValidationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class LazyMethodValidationConfigWithProxyTargetClass {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public static MethodValidationPostProcessor methodValidationPostProcessor(@Lazy Validator validator) {
|
||||||
|
MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
|
||||||
|
postProcessor.setValidator(validator);
|
||||||
|
postProcessor.setProxyTargetClass(true);
|
||||||
|
return postProcessor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue