zoukankan      html  css  js  c++  java
  • @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);
        }
    }

    日志:

  • 相关阅读:
    进程Queue
    进程ID
    多进程
    queue 生产者、清费者
    让静态页面显示用户登录状态
    apache2.2 + tomcat6 整合以及集群配置整理
    linux安装rzsz
    http_load
    用Ant实现Java项目的自动构建和部署
    Openfire:安装指南
  • 原文地址:https://www.cnblogs.com/mufeng07/p/12512591.html
Copyright © 2011-2022 走看看