I have an event handler that runs perfectly fine on a repository. However once I add a controller into the mix and call the repository method directly, the EventHandler seems to be skipped over.
Has anyone encountered this "issue"? If so, what can I do to get the event handler to start running again?
So you expect that your event handler is called when you use a custom controller. I think this expectation is false. The event handler is just called when spring data rests RepositoryEntityController
is in control. It is not an entity event listener on JPA level.
What you could do is call the event handler manually. The spring-data-rest RepositoryEventHandler
is a using normal spring application events. So your controller could implement ApplicationEventPublisherAware
and publish one of the spring-data-rest application events. These are all subclasses of org.springframework.data.rest.core.event.RepositoryEvent
applicationEventPublisher.publishEvent(new AfterCreateEvent(myEntity));
See the spring documentation for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With