• Spring Boot2.0之多数据源事务管理


    结合前面做的小项目,如果我把test01 test02下面的 service 都加了 事务的注解

    这样启动时候会报错!

    事务管理器里面不能有两个事务!!!!

    这时候需要用  @Transactional(transactionManager="test1TransactionManager")  指定事务管理器

    请看当前目录结构:

    DataSource1Config代码里面有声明事务管理器的名字的!

     然后我们这个项目多个数据源、多个事务

     同理可得:

    package com.toov5.test02.service02;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import com.toov5.test02.mappertest02.UserMapperTest02;
    
    import lombok.extern.slf4j.Slf4j;
    
    @Service
    @Slf4j
    public class UserService02 {
      @Autowired
      private UserMapperTest02 userMapperTest02;
      
      @Transactional(transactionManager="test2TransactionManager")
      public int insertUser(String name, Integer age){
         int result = userMapperTest02.insert(name, age);
          log.info("####################",result);
          return result;
      }
    }

     当失败时候,会进行回滚从而不会写入到数据库中

  • 相关阅读:
    [NOIP2018校模拟赛]T2矩阵分组 Matrix
    [NOIP2018校模拟赛]T1聚会 party
    python写一个邮箱伪造脚本
    python抢火车票的脚本
    git的使用
    python写一个翻译的小脚本
    python写的一个集合
    python调用metasploit里的MS-17-010模块进行漏洞攻击
    ssh爆破篇
    python查询完结篇
  • 原文地址:https://www.cnblogs.com/toov5/p/9820116.html
Copyright © 2020-2023  润新知