spring boot mysql 事务
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 事务的更多相关文章
- 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 ...
- spring boot 分布式事务实现(XA方式)
关于spring boot 支持分布式事务,XA是常用的一种方式. 这里把相关的配置记下,方便以后使用. 首先配置两个不同的数据源 : 订单库.持仓库. /** * Created by zhangj ...
- Spring Boot使用事务不起作用
今天使用spring boot做关于事务的demo时发现在service层使用@Transactional注解运行之后遇到错误并不能回滚. @Service public class HelloCon ...
- spring boot +mysql + mybatis + druid的整理(一)——单数据源
一,使用spring boot脚手架搭建spring boot框架生成maven项目 如下图所示: 设置自定义的坐标,即左侧的Group和Artifact,右侧可以搜索添加一些依赖,搜索不到的可以在p ...
- 【docker-compose】使用docker-compose部署运行spring boot+mysql 【处理容器的时区问题】【详解】【福利:使用docker-compose构建 wordpress+mysql】
==================================================================================================== ...
- spring boot开启事务管理,使用事务的回滚机制,使两条插入语句一致
spring boot 事务管理,使用事务的回滚机制 1:配置事务管理 在springboot 启动类中添加 @EnableTransactionManagement //开启事务管理 @Enable ...
- spring boot mysql和mybatis
1 选择mysql驱动 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connecto ...
- spring boot jpa 事务管理
spring boot 对jpa的支持极为方便,基本上不需要作太多配置,只需要加上注解就能支持事务: @Controller @Transactional(rollbackOn = Exception ...
- 集成spring boot + mysql + docker实战
前言 网上找过很多文章,关于通过docker构建mysql容器并将应用容器和docker容器关联起来的文章不多.本文将给出具体的范例.此处为项目的源码 前置条件 该教程要求在宿主机上配置了: dock ...
随机推荐
- 【Boost】boost库中timer定时器 2
博客转载自:http://blog.csdn.net/yockie/article/details/40386145 先跟着boost文档中asio章节的指南中的几个例子学习一下使用: 所有的Asio ...
- Entity Framework Tutorial Basics(5):Create Entity Data Model
Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...
- Entity Framework Tutorial Basics(3):Entity Framework Architecture
Entity Framework Architecture The following figure shows the overall architecture of the Entity Fram ...
- mysql--笔记1
今日内容介绍1.MySQL数据库2.SQL语句=========================================================1 数据库概念 1.1: 什么是数据库 ...
- WebGoat系列实验Injection Flaws
WebGoat系列实验Injection Flaws Numeric SQL Injection 下列表单允许用户查看天气信息,尝试注入SQL语句显示所有天气信息. 选择一个位置的天气,如Columb ...
- Java之命令模式(Command Pattern)
转自:http://www.cnblogs.com/devinzhang/archive/2012/01/06/2315235.html 1.概念 将来自客户端的请求传入一个对象,从而使你可用不同的请 ...
- DjVu、PDF中的隐藏文本
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2012.06.11 目录一.背景二.DjVu中的隐藏文本三.PDF中的隐藏文本 一.背景 目前对于扫描电子文档,网上比较流行 ...
- HttpRunnerManager接口自动化测试框架测试报告页面优化
在测试报告生成结果页面,点击左上角的图标不能快速返回到首页.在大神的指点下,要改一个跳转链接,如下图: 修改路径如下: 修改的字段:把<a href="#!" class=& ...
- iOS的iPhone屏幕尺寸、分辨率、PPI和使用123倍图
- D - Back and Forth(模拟)
Problem Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis point ...