Created
May 27, 2014 18:29
-
-
Save rkroll/016814536d34fc0f2f97 to your computer and use it in GitHub Desktop.
Sprint Transaction + ApplicationEventPublisher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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