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);
}