No transaction aspect-managed TransactionStatus in scope

   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

上一篇:php index.php的逻辑问题


下一篇:面试官没想到,一个 Java 线程生命周期,我可以扯半小时