I am using SpringDataJPA 5.1 and Hibernate 5.3.9 including hibernate-envers. I don’t know how to inject spring beans into the hibernate envers custom RevisionListener.
I have tried
(@Service or @Component)
public class ExtendedRevisionListener implements RevisionListener {
@Autowired
private MyService myService;
void newRevision(Object revisionEntity){
myService.doSomething(…)
}
}
Of course the class is included in the @ComponentScan packages resolution. A problem is that myService is not injected into the listener.
In the hibernate-envers documentation:
As of Hibernate Envers 5.3, dependency injection is now supported for a RevisionListener. This feature is up to the various dependency frameworks, such as CDI and Spring, to supply the necessary implementation during Hibernate ORM bootstrap to support injection. If no qualifying implementation is supplied, the RevisionListener will be constructed without injection.
Unfortunatelly i haven’t found any working example.