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. CCNA实验(4) -- EIGRP

    enableconf tno ip do loenable pass ciscoline con 0logg syncexec-t 0 0line vty 0 4pass ciscologg sync ...

  2. m文件转换为C/C++文件的编译、绘图、参数、打包问题总结

    在工程计算相关项目中,常常利用Matlab来完成计算.算法.绘图等功能.使用Matlab来完成这些功能非常简单,Matlab提供的m编程语言功能强大,代码量少.为了在自己的C/C++项目中加入这些功能 ...

  3. DrawerLayout、CoordinatorLayout、CollapsingToolbarLayout的使用--AndroidSupportDesign练手

    先po一张效果图 PS:原谅题主的懒惰吧.. 看着是不是很酷炫,那是因为5.0的动画做得好,代码其实没有多少,搞清楚这个布局的层次关系很重要. 废话不多说了,先来看布局文件 最外层是一个DrawerL ...

  4. andrewchilds/jQuery.DomOutline

    andrewchilds/jQuery.DomOutline DOM - 使用Javascript:让用户选择一个类似Firebug的HTML元素? -

  5. ubuntu12.04下 安装虚拟主机

    Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...

  6. c#打印记忆功能

    下面这些实例都可以拷下直接用 总体思路:保存打印设置信息到本地文件,下次打印的时候直接读取文件信息,通过序列化与反序列化来获取值.本例只是针对打印的横纵向进行设置,读者也可以增加其他设置信息进行保存读 ...

  7. 史上最简单的Hibernate入门简单介绍

    事实上Hibernate本身是个独立的框架,它不须要不论什么web server或application server的支持.然而,大多数的Hibernate入门介绍都加入了非常多非Hibernate ...

  8. 倒计时IE6+

    很简单的 下面是我为了做多个倒计时更改之后的 dome 下载链接   兼容 IE7以上 IE6没测试应该没问题 http://yunpan.cn/cf29rxmGKuMyJ  提取码 ca61

  9. ios学习Day3xiawu

    switch #include <stdio.h> int main(int argc, char * argv[]) { int i; scanf("%d",& ...

  10. 【JS控制图片显示的大小(图片等比例缩放)】

    效果: 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...