TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization(){ @Override public void afterCompletion(int status) { //业务方法 } } });
TransactionSynchronizationManager.registerSynchronization有以下的,根据你业务去重写即可
- suspend:在spring开启新事务,获取connection之前会调用(未执行registCustomer)
- resume:开启新事务失败时会调用(未执行registCustomer)
- flush:没调用
- beforeCommit:事务提交前会调用(已执行registCustomer)
- beforeCompletion:事务提交前会调用,在beforeCommit之后(已执行registCustomer)
- afterCommit:事务提交后会调用(已执行registCustomer)
- afterCompletion:事务提交后会调用,在afterCommit之后(已执行registCustomer)