Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

Philipp Foermer opened SPR-17273 and commented

Is
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.

@Repository
public class LegacyDao {

    @NotNull
    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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions