From Hibernate 6.2 it is mandatory enabled CDI extensions to work with Spring Container, this is included in Spring 3.1 in the class {{HibernateJpaVendorAdapter}} (spring-orm).
!image-20230703-065313.png|width=526,height=65!
The problem it is in the class {{DefaultRevisionInfoGenerator}} (hibernate-envers) when the method {{resolveRevisionListenerBean}}. The condition {{Helper.allowExtensionsInCdi( serviceRegistry )}}should be negated to allow use Spring Container.
{code:java}private ManagedBean<? extends RevisionListener> resolveRevisionListenerBean( Class<? extends RevisionListener> listenerClass, ServiceRegistry serviceRegistry) { if ( !listenerClass.equals( RevisionListener.class ) ) { if ( Helper.allowExtensionsInCdi( serviceRegistry ) ) { return new ProvidedInstanceManagedBeanImpl<>( FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( listenerClass ) ); } return serviceRegistry.getService( ManagedBeanRegistry.class ).getBean( listenerClass ); } return null; } {code}
To reproduce you can use my demo to test it, [mgvinuesa/hibernate-envers-spring: A demo of how to wire Spring Framework 5.1+ to inject beans into Hibernate Envers RevisionListener (github.com)|https://github.com/mgvinuesa/hibernate-envers-spring]
If you change the spring boot version to 3.0, everything works properly, but when it is updated to 3.1, the RevisionListener does not work properly and you could see in the log the following message:
{noformat}MyService was not injected . {noformat} |
|