mysql默认 事务自动提交。即:每条insert/update/delete语句,不需要程序手工提交事务,而是mysql自行提交了。

如果我们想实现程序事务提交,需要事先关闭mysql的自动提交事务。

但是,如果采用spring管理事务,不需要实现关闭mysql自动提交事务的,因为,spring会帮你关闭mysql的自动提交事务。

spring:

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable transaction annotation support -->
<tx:annotation-driven transaction-manager="txManager" />

springboot:

1)、启动类上加@EnableTransactionManagement

@EnableTransactionManagement
@SpringBootApplication
@Slf4j
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
log.info("PortalApplication is success!");
}
}

service的方法上加:@Transactional

@Transactional(readOnly = false, rollbackFor = Exception.class)
public AddProjectInfoDto.Resp addPrj(AddProjectInfoDto.Req req) {
...
}

spring boot mysql 事务的更多相关文章

  1. FW: How to use Hibernate Lazy Fetch and Eager Fetch Type – Spring Boot + MySQL

    原帖 https://grokonez.com/hibernate/use-hibernate-lazy-fetch-eager-fetch-type-spring-boot-mysql In the ...

  2. spring boot 分布式事务实现(XA方式)

    关于spring boot 支持分布式事务,XA是常用的一种方式. 这里把相关的配置记下,方便以后使用. 首先配置两个不同的数据源 : 订单库.持仓库. /** * Created by zhangj ...

  3. Spring Boot使用事务不起作用

    今天使用spring boot做关于事务的demo时发现在service层使用@Transactional注解运行之后遇到错误并不能回滚. @Service public class HelloCon ...

  4. spring boot +mysql + mybatis + druid的整理(一)——单数据源

    一,使用spring boot脚手架搭建spring boot框架生成maven项目 如下图所示: 设置自定义的坐标,即左侧的Group和Artifact,右侧可以搜索添加一些依赖,搜索不到的可以在p ...

  5. 【docker-compose】使用docker-compose部署运行spring boot+mysql 【处理容器的时区问题】【详解】【福利:使用docker-compose构建 wordpress+mysql】

    ==================================================================================================== ...

  6. spring boot开启事务管理,使用事务的回滚机制,使两条插入语句一致

    spring boot 事务管理,使用事务的回滚机制 1:配置事务管理 在springboot 启动类中添加 @EnableTransactionManagement //开启事务管理 @Enable ...

  7. spring boot mysql和mybatis

    1 选择mysql驱动 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connecto ...

  8. spring boot jpa 事务管理

    spring boot 对jpa的支持极为方便,基本上不需要作太多配置,只需要加上注解就能支持事务: @Controller @Transactional(rollbackOn = Exception ...

  9. 集成spring boot + mysql + docker实战

    前言 网上找过很多文章,关于通过docker构建mysql容器并将应用容器和docker容器关联起来的文章不多.本文将给出具体的范例.此处为项目的源码 前置条件 该教程要求在宿主机上配置了: dock ...

随机推荐

  1. SQL查询语句 [1]

    一.使用字符串作为条件查询 在 Home/controller/UserController.class.php 下插入 <?php namespace Home\Controller; use ...

  2. 机器人自主移动的秘密,从SLAM技术说起(一)

    博客转载自:https://www.leiphone.com/news/201609/c35bn1M9kgVaCCef.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...

  3. SimpleFactoryPattern(23种设计模式之一)

    设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...

  4. Luogu 2827 [NOIP2016] 蚯蚓

    原来真的是按题意模拟啊,还以为有高能的算法可以直接算每个$t$的值. 考虑到先切的蚯蚓一定比后切的蚯蚓长,于是可以弄三个队列分别存放原来的序列和两个切开后的序列,每次取出三个队头的最大值进行扩展. 考 ...

  5. c语言中会遇到的面试题

    预处理器(Preprocessor) 1 . 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题)         #define SECONDS_PER_YEAR (60 ...

  6. form的提交方式

    1,最普通最常用的方法就是用submit type.. <form name=”form” method=”post” action=”#"> <input type=”s ...

  7. Java50道经典习题-程序46 字符串连接

    题目:编写一个两个字符串连接的程序 import java.util.Scanner; public class Prog46 { public static void main(String[] a ...

  8. C#模拟进度条

    自己看源码 using System; namespace ConsoleTest { class Program { static void Main(string[] args) { Consol ...

  9. Javascript的对象分类

    返回索引 按W3CSchool分类 1.JS内置对象 在W3CShool中对应JavaScript对象  参考

  10. JavaWeb中MVC的使用--以管理系统举例

    开发环境:JavaSE1.7.JavaEE7.0.JSTL1.2.2.Web2.3.MySQL5.5.28 系统分析与功能设计: 本系统实现商品信息的管理,应包括以下几个功能: 商品信息列表:列出所有 ...