cjchalmers
09/01/2025, 7:45 PMjdaugherty
09/01/2025, 7:52 PMclass EventService implements ApplicationEventPublisherAware {
private ApplicationEventPublisher publisher
void publish(MyEventClass applicationEvent) {
if (publisher) {
publisher.publishEvent(applicationEvent)
}
}
@Override
void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher
}
}
As for subscribing to events, you add a method on a bean and annotate it with either @EventListener or @TransactionalEventListener . You'll want to use TransactionEventListener with @Async to asynchronously trigger a response.
@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, condition = '#event.myEnum == T(com.example.MyEnum).CREATE')
void myResponseMethod(MyEventClass event)
Note that the syntax for the event listener uses spring eljdaugherty
09/01/2025, 7:53 PMjdaugherty
09/01/2025, 7:54 PMcjchalmers
09/01/2025, 8:11 PM