@Resource private TransactionTemplate transactionTemplate; boolean flag = transactionTemplate.execute(status -> { // do ... return true; }); @Transactional(rollbackFor = RuntimeException.class)