I need to call some method after transaction succes or rollback. I am using as
Using Spring 4+: The easiest/cleanest way without using global aspects and configurations is based on my answer here: https://stackoverflow.com/a/43322052/986160
If you need a callback on a @Transactional method after it successfully commits just add that in the beginning of the method:
@Service
public class OneService {
@Autowired
OneDao dao;
@Transactional
public void a transactionalMethod() {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter(){
public void afterCommit(){
//do stuff right after commit
System.out.println("commit!!!");
}
});
//do db stuff
dao.save();
}
}