1.配置普通的 controller,service ,dao 的bean.

<!-- 配置 dao ,service -->
<bean id="bookShopDao" class="com.liujl.spring.tx.xml.BookShopDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean> <bean id="bookShopService" class="com.liujl.spring.tx.xml.serivice.impl.BookShopServiceImpl">
<property name="bookShopDao" ref="bookShopDao"></property>
</bean> <bean id="cashier" class="com.liujl.spring.tx.xml.serivice.impl.CashierImpl">
<property name="bookShopService" ref="bookShopService"></property>
</bean>

2.配置事务管理器bean

<!-- 配置事务管理器 hibernate、jpa都是类似的这样配 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

3.引入 tx 命名空间

xmlns:tx="http://www.springframework.org/schema/tx"

4.配置事务各个属性(方法名可以使用通配符*)

<!-- 配置事务属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="purchase" propagation="REQUIRED"/>
<tx:method name="checkout" propagation="REQUIRED"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
</tx:attributes>
</tx:advice>

5.引入aop命名空间

xmlns:aop="http://www.springframework.org/schema/aop"

6.配置事务的切点,并把事务切点和事务属性关联起来

<!-- 配置事务的切点,并把事务切点和事务属性不关联起来 -->
<aop:config>
<aop:pointcut expression="execution(* com.liujl.spring.tx.xml.serivice.*.*(..))" id="txPointCut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
</aop:config>
 事务的属性:  
    1.使用 propagation 声明事务的传播属性,默认即 REQUIRED 即被包含在上面的事务中,放弃自己处理事务
REQUIRES_NEW 以本方法为执行单位,开启一个新事务(外部事务在方法执行前后被挂起) 2.使用 isolation 指定事务的隔离级别,最常用的取值为 READ_COMMITTED 读与提交
    3.默认情况下Spring 的声明式事务对所有的运行时一样长进行回滚
也可以对应的属性指定配置,通常情况下取默认值即可。使用 noRollbackFor 指定不回滚的异常,其他的类似
    4.使用 readOnly 指定事务是否为只读,表示这个事务只读取数据但不更新数据,
这样可以帮助数据库引擎优化事务。若真的是一个只读取数据库值得方法,应设置readOnly=true
    5.使用 timeout 指定强制回滚之前事务可以占用的时间

spring4声明式事务—02 xml配置方式的更多相关文章

  1. spring4声明式事务—02 xml配置方式

    1.配置普通的 controller,service ,dao 的bean. <!-- 配置 dao ,service --> <bean id="bookShopDao& ...

  2. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

  3. 事务之三:编程式事务、声明式事务(XML配置事务、注解实现事务)

    Spring2.0框架的事务处理有两大类: JdbcTemplate操作采用的是JDBC默认的AutoCommit模式,也就是说我们还无法保证数据操作的原子性(要么全部生效,要么全部无效),如: Jd ...

  4. Spring声明式事务管理与配置介绍

    转至:http://java.9sssd.com/javafw/art/1215 [摘要]本文介绍Spring声明式事务管理与配置,包括Spring声明式事务配置的五种方式.事务的传播属性(Propa ...

  5. Spring声明式事务如何选择代理方式?

    Spring声明式事务如何选择代理方式   解决方法: 1.基于注解方法: <tx:annotation-driven transaction-manager="txManager&q ...

  6. spring4声明式事务--01注解方式

    1.在spring配置文件中引入 tx 命名空间 xmlns:tx="http://www.springframework.org/schema/tx" 2.配置事务管理器 < ...

  7. Spring声明式事务管理与配置详解

    转载:http://www.cnblogs.com/hellojava/archive/2012/11/21/2780694.html 1.Spring声明式事务配置的五种方式 前段时间对Spring ...

  8. SpringMVC+Spring+Mybatis整合,使用druid连接池,声明式事务,maven配置

    一直对springmvc和mybatis挺怀念的,最近想自己再搭建下框架,然后写点什么. 暂时没有整合缓存,druid也没有做ip地址的过滤.Spring的AOP简单配置了下,也还没具体弄,不知道能不 ...

  9. Spring添加声明式事务

    一.前言 Spring提供了声明式事务处理机制,它基于AOP实现,无须编写任何事务管理代码,所有的工作全在配置文件中完成. 二.声明式事务的XML配置方式 为业务方法配置事务切面,需要用到tx和aop ...

随机推荐

  1. D. GCD Counting(树上dp)

    题目链接:http://codeforces.com/contest/1101/problem/D 题目大意:给你n个点,每个点都有权值,然后给你边的关系,问你树上的最大距离.(这里的最大距离指的是这 ...

  2. sparse coding

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  3. CentOS配置163yum源

    1.下载repo文件 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 2.备份并替换系统的repo文件 [root@localhost ...

  4. 简单的UDP接受程序

    //功能:客服端发送UDP包,服务器接受到并打印出来//2015.9.13成功 #include <stdio.h>#include <sys/socket.h>#includ ...

  5. No.19 selenium学习之路之os模块

    os模块没有什么好说的,直接看实例就可以了 读取文件内容: open只能读文件的内容,不能读文件夹的内容 常用方法: 1. os.name——判断现在正在实用的平台,Windows 返回 ‘nt'; ...

  6. 如何阻止点击scrollviewer里面的单位内容时,自动滚动

    <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="FocusVisualStyle ...

  7. const 和 #define区别_fenglovel_新浪博客

    const 和 #define区别 (2012-12-11 14:14:07) 转载▼ 标签: 杂谈   (1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行阶段使 ...

  8. sql server 2005/2008R2 报“红叉”错,即“不允许所请求的注册表访问权”的错误

    一.使用报错展示:           1.红叉错: 2.报错文字信息: 解决办法:可以鼠标右键,以管理员的身份运行即可,但这治标不治本,按如下方法可以彻底解决:把“以管理员身份运行此程序”勾上,即可

  9. LeetCode282. Expression Add Operators

    Given a string that contains only digits 0-9 and a target value, return all possibilities to add bin ...

  10. 阿里百川码力APP监控 来了!

    阿里百川码力APP监控  来了!这个APP监控 和手淘一起成长历经千锤百炼 走过千BUG万坑如今百川起产品   为了让你的APP更好 用户更爽! 在移动互联网时代,一款应用是否成功,用户体验是一个关键 ...