首页 > Web开发 > 详细

No transaction aspect-managed TransactionStatus in scope

时间:2021-09-22 00:54:59      阅读:7      评论:0      收藏:0      [点我收藏+]
   org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope

出错

    @Async
    public Future<Boolean> test(){
        return delete();
    }
    @Transactional(rollbackFor = Exception.class)
    public Future<Boolean> delete(){
        jdbcTemplate.update("delete from tb_name");
        jdbcTemplate.update("delete from tb_age");
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return new AsyncResult<>(true);
    }

改成

    // 放一起
    @Async
    @Transactional(rollbackFor = Exception.class)
    public Future<Boolean> test(){
        return delete();
    }
    
    public Future<Boolean> delete(){
        jdbcTemplate.update("delete from tb_name");
        jdbcTemplate.update("delete from tb_age");
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return new AsyncResult<>(true);
    }

No transaction aspect-managed TransactionStatus in scope

原文:https://www.cnblogs.com/freeatalk/p/15311756.html

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!