Does anyone have a good tutorial or some advice on how to implement one\'s own XAResource? I need Spring\'s MailSender to be transactional, so that the mail will only be sent on
You can use a TransactionSynchronizationManager.registerSynchronization
(like gpeche mentioned) with a TransactionSynchronizationAdapter
which has a variety of methods that are called at various stages of the current transaction. I think the most suitable method for the question is the afterCommit.
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
super.afterCommit();
sendEmail();
}
});