-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
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