spring boot 的事务管理
来源:互联网 发布:淘宝网韩国身体去角质 编辑:程序博客网 时间:2024/06/01 08:20
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:task="http://www.springframework.org/schema/task"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "><!-- mybatis事务管理 --> <!--<tx:annotation-driven transaction-manager="transactionManager" />--><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"/></bean><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="get*" read-only="true" /><tx:method name="set*" read-only="true" /><tx:method name="query*" read-only="true" /><tx:method name="find*" read-only="true" /><tx:method name="load*" read-only="true" /><tx:method name="count*" read-only="true" /><tx:method name="save*" rollback-for="Exception"/><tx:method name="add*" rollback-for="Exception" /><tx:method name="update*" rollback-for="Exception" /><tx:method name="delete*" rollback-for="Exception" /><tx:method name="merage*" rollback-for="Exception" /></tx:attributes></tx:advice><aop:config><aop:pointcut id="serviceOperation" expression="execution(* com.jointem..*service..*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" /></aop:config></beans>
方法一:注解的事物管理
在进行数据库操作的时候就会遇到事务管理,插入的时候要加@Transactional注解进行事务的回滚。两个插入语句如果其中一个执行失败,则两条插入语句都不能执行。
方法二:spring配置文件的事务管理,如上面代码所示
1声明式事务管理
1)配置事物管理器
2)配置注解驱动
3)在方法或类上面添加@Transactional,事务传播性,就是一个事务调用另外一个事务,是用当前事务,还是重新开启一个事务,举个例子就是你去餐厅吃饭,遇到熟人,有两种选择,一种是加入他们做一桌吃饭,一起吃饭,一起离开。另外一种是重新安排一桌吃饭。一个去赋予一个买多本书的操作,他的钱买三不够,买两个够,在付款的时候就给事务添加一个属性,propagation=Propagation.REQUIRED,开启新事物REQUIRED_NEW
这个注解用到了一个切面编程,用了这个注解开启一个事务,函数体处理请求,然后自动提交函数,sessionFactory整合mybaties和spring。
阅读全文
0 0
- spring boot 的事务管理
- Spring Boot中的事务管理
- Spring Boot中的事务管理
- Spring Boot中的事务管理
- spring boot 中的事务管理
- 5、spring-boot事务管理
- Spring Boot中的事务管理
- Spring Boot中的事务管理
- spring boot 事务管理
- Spring Boot中的事务管理
- Spring boot事务管理只异常不回滚的解决方案
- Spring , Spring的事务管理
- 12.玩转Spring Boot 事务管理
- spring boot配置mybatis和事务管理
- spring boot配置mybatis和事务管理
- Spring boot +mybatis 实现声明式事务管理
- spring boot配置mybatis和事务管理
- spring boot学习(五)---事务管理
- OpenCV处理指定帧画面
- 【Unity3D问题之EnhanceScollView选择角色3D循环滚动效果实现】
- swift 4.0 版本 无限轮播图
- Python中flatten,matrix.A用法
- 手把手教你用7行代码实现微信聊天机器人 -- Python wxpy
- spring boot 的事务管理
- linux IO子系统和文件系统读写流程
- java后台返回当前日期前30天的数据并排序
- oracle 11g,创建用户,表空间,赋予用户权限,导入dmp
- 匠牛社区AM5728开发板开机登陆
- Python中的X[:,0]和X[:,1]
- input type=“color”
- echarts jsp实时更新动态折线图
- 五分钟学GIS | 立体效果地图制作