1、声明式实现事务管理

  XML命名空间定义,定义用于事务支持的tx命名空间和AOP支持的aop命名空间:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 事务管理器,对mybatis操作数据库 控制。spring使用jdbc的事务控制类-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 :dataSource在dao中配置-->
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为,规范开发接口-->
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice> <!-- 调用通知:aop -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* edu.mybatis.service.impl.*.*(..))"/>
</aop:config>
</beans>

<bean id="transactionManager" class="...">用来定义事务管理器

<tx:advice>标签用于事务通知,用于指定事务,transaction-manager属性用来指定事务管理器,并且通过<tx:attributes>方法来指定具体需要拦截的方法

<tx:method name="save*">等方法是用来定义拦截一save头的方法,而且被拦截的方法应该配置事务属性:propagation="REQUIRED"表示传播行为是必须的,isolation:表示隔离级别,read-only=“true”,表示事务只读

<aop:config>声明进行Aop的配置,advice-ref属性用来指定通知,pointcut:用来定义切点

spring和mybatis整合进行事务管理的更多相关文章

  1. spring和hibernate整合,事务管理

    一.spring和hibernate整合开发步骤 1 引入jar文件,用户libarary列表如下 //spring_core spring3..9core\commons-logging-1.2.j ...

  2. Spring 与 mybatis整合---事务管理

    MyBatis与Spring整合前后事务管理有所区别 整合前:通过 session = sessionFactory.openSession(true); //或者是false 设置事务是否自动提交: ...

  3. Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...

  4. Mybatis学习--spring和Mybatis整合

    简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...

  5. spring与mybatis集成和事务控制

    一个. 基本介绍 本文将使用spring整合mybatis, 并加入事务管理, 以此为记, 方便以后查阅. 二. 样例 1. 代码结构图: 2. 建表语句: DROP DATABASE test; C ...

  6. SpringMVC, Spring和Mybatis整合案例一

    一  准备工作 包括:spring(包括springmvc).mybatis.mybatis-spring整合包.数据库驱动.第三方连接池. 二  整合思路 Dao层: 1.SqlMapConfig. ...

  7. Spring boot Mybatis 整合

    PS: 参考博客 PS: spring boot配置mybatis和事务管理 PS: Spring boot Mybatis 整合(完整版)   这篇博客里用到了怎样 生成 mybatis 插件来写程 ...

  8. Java基础-SSM之Spring和Mybatis整合案例

    Java基础-SSM之Spring和Mybatis整合案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   在之前我分享过mybatis和Spring的配置案例,想必大家对它们的 ...

  9. Spring boot Mybatis 整合(注解版)

    之前写过一篇关于springboot 与 mybatis整合的博文,使用了一段时间spring-data-jpa,发现那种方式真的是太爽了,mybatis的xml的映射配置总觉得有点麻烦.接口定义和映 ...

随机推荐

  1. 6_StopWatch

    6 // // ViewController.swift // StopWatch // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. Al ...

  2. PCB板常用知识简介——沉金板VS镀金板

    一.PCB板表面处理:  抗氧化,喷锡,无铅喷锡,沉金,沉锡,沉银,镀硬金,全板镀金,金手指,镍钯金 OSP: 成本较底,可焊性好,存储条件苛刻,时间短,环保工艺.焊接好 .平整 . 喷锡:喷锡板一般 ...

  3. Pro/Engineer wildfire 5.0 野火版系列下载及安装方法

    三.PTC Pro/Engineer wildfire 5.0 M030 野火版最新版 DVD 下载(多国语言) 1.野火下载站下载32&64位下载:[32位] http://down.pro ...

  4. Q_D宏

    Qt 源码中有很多Q_Q和Q_D宏,使用这些宏的地方总会看到有q指针和d指针,查了查KDE文档,大体搞清了其中的机理,欧也!Qt的这些私有数据访问策略还是挺值得借鉴.下面就简单总结一下. 访问器 , ...

  5. 也许有用(也谈VC中ModifyStyle&ModifyStyleEx无法改变控件的Style)

     一个View中用到了一个CListCtrl,在OnInitialUpdate函数里面他调用了m_listCtrl.ModifyStyleEx(0, LVS_EX_FULLROWSELECT);但是结 ...

  6. android raw与assets资源

    *res/raw和assets的同样点: 1.两者文件夹下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制. *res/raw和assets的不同点: 1.res/raw中的文件会被映射 ...

  7. Sql 字符串操作类COALESCE

    SqlServer中肯定有过将表中某列的值拼接成字符串,以","或者其他符号隔开的情况吧,一般情况我们会这样做: declare @returnValue nvarchar(max ...

  8. 10条影响CSS渲染速度的写法与建议

    1.*{} #zishu *{} 尽量避开由于不同浏览器对HTML标签的解释有差异,所以最终的网页效果在不同的浏览器中可能是不一样的,为了消除这方面的风险,设计者通常会在CSS的一个始就把所有标签的默 ...

  9. Hibernate中,left join、inner join以及left join fetch区别(转)

    标签: hibernate hql inner join left right 杂谈 分类: SQL 原文地址:http://m33707.iteye.com/blog/829725 Select F ...

  10. C++ typedef

    C++ typedef 作用:用来定义类型的同义词,用作类型的说明符. 用法:typedef typeName myTypeName; 使用目的:1. 为了隐藏特定类型的实现,强调使用类型的目的.2. ...