Skip to content

Instantly share code, notes, and snippets.

@rkroll
Created May 27, 2014 18:29
Show Gist options
  • Save rkroll/016814536d34fc0f2f97 to your computer and use it in GitHub Desktop.
Save rkroll/016814536d34fc0f2f97 to your computer and use it in GitHub Desktop.
Sprint Transaction + ApplicationEventPublisher
public <T extends ApplicationEvent> void publishEvent(final T event) {
if (TransactionSynchronizationManager.isActualTransactionActive()) {
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
delegate.publishEvent(event);
}
});
}
else {
delegate.publishEvent(event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment