title: dynamically register transaction listener with spring?
body: <p>I have a springframework application in which I would like to add a transaction listener to a transaction which is currently in progress.  The motivation is to trigger a post commit action which notifies downstream systems.  I am using @Transactional to wrap a transaction around some service method -- which is where I want to create/register the post transaction listener.  I want to do something "like" the following.</p>
  
  <pre><code>public class MyService {
   @Transaction
   public void doIt() {
    modifyObjects();
  
    // something like this
    getTransactionManager().registerPostCommitAction(new 
     TransactionSynchronizationAdapter() {
       public void afterCommit() { 
        notifyDownstream(); 
       }
    });
   }
  }
  </code></pre>
  
  <p>Spring has a TransactionSynchronization interface and adapter class which seems exactly what I want; however it is not immediately clear how to register one dynamically with either the current transaction, or the transaction manager.  I would rather not subclass JtaTransactionManager if I can avoid it.</p>
  
  <p><strong>Q:</strong> Has anyone done this before.</p>
  
  <p><strong>Q:</strong> what is the simplest way to register my adapter?</p>