首先函数一定要有@Transactional
然后,任意位置添加这段
TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { runnable.run(); } } );
如果要实现cancel,可以参考 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/support/TransactionSynchronization.html