码迷,mamicode.com
首页 > 其他好文 > 详细

@Async异步不影响事务提交@Transaction

时间:2020-03-17 19:31:25      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:com   cep   llb   public   wired   art   http   事务   new   

测试代码

@Service
public class TestServiceImpl implements ITestService {
    @Resource
    private IStudentMapper studentMapper;
    @Autowired
    private IAsyncService asyncService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveUser(Student student) {
        studentMapper.insert(student);
        asyncService.test(student);
    }
}
@Service
public class AsyncServiceImpl implements IAsyncService {
    @Async("executor")
    @Override
    public void test(Student student) {
        System.out.println(1/0);
    }
}

测试类:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = StartBootMybatisApplication.class)
public class Test1 {
    @Autowired
    private ITestService testService;
    @Test
    public void test1(){
        Student student=new Student();
        student.setSno("112");
        student.setSname("小明");
        student.setSsex("男");
        student.setSclass("95032");
        student.setSbirthday(new Date());
        testService.saveUser(student);
    }
}

日志:

技术图片

 

@Async异步不影响事务提交@Transaction

标签:com   cep   llb   public   wired   art   http   事务   new   

原文地址:https://www.cnblogs.com/mufeng07/p/12512591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!