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

BeanValidationPostProcessor(afterInitialization=true) fails for cglib proxied bean [SPR-17273] #21806

spring-projects-issues opened this issue Sep 13, 2018 · 1 comment
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Sep 13, 2018

Philipp Foermer opened SPR-17273 and commented

An instance of "org.springframework.validation.beanvalidation.BeanValidationPostProcessor" with property "afterInitialization=true" fails to validate a bean instance for which a cglib proxy has been created around.

Example: If a bean class declares a javax.validation.NotNull constraint for a bean property, then the validation fails on the cglib proxy instance as Spring uses delegation for proxies and the bean property is null on the cglib proxy instance.

public class LegacyDao {

    private SessionFactory sessionFactory; 

    public void setSessionFactory(SessionFactory sessionFactory) {
       this.sessionFactory = sessionFactory;


For LegacyDao Spring creates an AOP proxy around for PersistenceExceptionTranslator, because of the Repository annotation. If LegacyDao is validated by BeanValidationPostProcessor(afterInitialization=true), then the validation fails.
Exepected behaviour
Validation performed by BeanValidationPostProcessor for a proxy instance should be done on the ultimate target object and not on intermediate proxy instances.


Affects: 4.3.17

Referenced from: commits 77887ef

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 13, 2018

Juergen Hoeller commented

Since this changes the actual object to validate in such a scenario and introduces a dependency on org.springframework.aop (which is commonly present for spring-context but technically optional), I've only revised this for 5.1.

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.1 GA milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants