Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodValidationPostProcessor does not support JDK proxy from FactoryBean [SPR-17431] #21964

spring-issuemaster opened this issue Oct 25, 2018 · 1 comment


Copy link

@spring-issuemaster spring-issuemaster commented Oct 25, 2018

Yanming Zhou opened SPR-17431 and commented

package com.example;

import static org.junit.Assert.assertEquals;

import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import javax.validation.constraints.NotEmpty;

import org.aopalliance.intercept.MethodInterceptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.validation.annotation.Validated;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

import com.example.MethodValidationPostProcessorTests.MyConfiguration;

@ContextConfiguration(classes = MyConfiguration.class)
public class MethodValidationPostProcessorTests {

	private MyInterface myInterface;

	private MyInterface myImplementation;

	@Test(expected = ConstraintViolationException.class)
	public void testJdkProxy() throws Exception {
		assertEquals("", myInterface.echo(""));

	@Test(expected = ConstraintViolationException.class)
	public void testImplementation() throws Exception {
		assertEquals("", myImplementation.echo(""));

	public interface MyInterface {

		public String echo(@NotEmpty String text);


	static class MyConfiguration {

		public FactoryBean<MyInterface> myInterface() {
			return new FactoryBean<MyInterface>() {

				public MyInterface getObject() throws Exception {
					return (MyInterface) new ProxyFactory(MyInterface.class,
							(MethodInterceptor) mi -> mi.getArguments()[0])

				public Class<?> getObjectType() {
					return MyInterface.class;


		public MyInterface myImplementation() {
			return new MyInterface() {

				public String echo(String text) {
					return text;


		public LocalValidatorFactoryBean validatorFactory() {
			return new LocalValidatorFactoryBean();

		public static MethodValidationPostProcessor methodValidationPostProcessor(@Lazy Validator validator) {
			MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
			return postProcessor;



testImplementation() pass and testJdkProxy() failed

Affects: 5.1.1

Issue Links:

  • #21907 MethodValidationPostProcessor validates FactoryBean methods for which validation is not applicable
  • #21919 MethodValidationPostProcessor still validates FactoryBean methods on CGLIB proxies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.