@Async异步不影响事务提交@Transaction
Posted mufeng07
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@Async异步不影响事务提交@Transaction相关的知识,希望对你有一定的参考价值。
测试代码
@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的主要内容,如果未能解决你的问题,请参考以下文章