上一篇文章中,银行转账业务没有使用事务,会出现问题,所以这篇文章对上篇文章出现的问题进行修改。

事务 依赖 AOP , AOP需要定义切面, 切面由Advice(通知) 和 PointCut(切点) 组成 !

项目结构图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUwAAAEyCAIAAAAeJH65AAAgAElEQVR4nO2df3AU14HnO39c7T9XdanKVbnylyvZW0Kg4rMAOcmEaLkkZ/lurw5fUrKlrMkSOzVrzDoIxw5gUEACyYoAp9eWAAcQIrbGYyBrB5kBLVaE7EVCCcGAwWg1K8QgCUkjjRj0s6URvPujZ3ped7/uftOa0Wh6vp96RU2/eb9GzFff1z3TXwkEAJAmJEnq6enp7+8PhUJ3KcLhsPyvwr1790ZHR4PBoNJ3zT9tPfWXO3/8fOTKAKHLqb/c2V/fQE8hpOOlAQAIcZjIP738SfWHezc0NFR/uPfTy5/Mz6QALHCcI/JPL3+yoaHBf7FO6r+woaHBdeoz6BwAktEiv/L7LUohhHjPdpDx7htXa853VZy69tuimmNPb/amYl4L/KJLcIn+1E/kc8/PPOlh3n6MWUCmivzyiS3qw80bGhpO/Pvnb587/I7vf9Ue/sH6kiNFP5+LyH1uIYrbl0g/++9OZUa+Ce2IPMEp0kg2ibzrWH5NSX7NsVZCei5W59eUrLsY1DRpbSzJr6n2jrAHkHsppapL/XSGibym9Nc1pb+uKa2cGaydGayd7N43fGV3T0vJv5/cuKGh4XstgaL6UyX/+P1Xfl78w5+/v3HrXrvz+NxxHfhF1zxIIj4LPbcZCYucZwq/6ErjL4D0zp42uo7lN16XH/ZcrM73Vq/ztvTQDUZa1tVYiTw2AoOFKPLm5ubKykrmU7/eurf8ny+Qex/ry6eXP3mmtv37v7n27MYTTz379lPP7rR/Tu4XXWl0EU71zmW7btgXIk8DGpE3tni9KjfuuVi97mJLlXNE3tTUtHTp0kWLFhk1eGnjm2SogVEI+fTyJ3tL3n3uZ7/d9pJoqPCg18vYDmlgWp38FtRv46l6l+iPv1F9bsElitHmlKaUEVyi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dg5FwYObl1xptqI64NW2TEualjjI1y4DQn2KysNZO4OH3EGofImR39oujTdQELDDg5F0ZOHn3WLONNfblKVDu5Ps5NLXLDHDgfewKOuDjmtTLtmOxkONZFNpMrh2CBACfnwuSc3FbGGw9z9EZYK4gCJ+dCUH+tVePkqQEiB8kBTj5XbGW88QCRg+QAJwfA4cDJAXA4cHIAHA6cHACHAycHwOHAyQFwOHByABwOnJwLwX7GW1L/dO6CDWNasAsDcHJOBPvxT3MWufaulgWppQW7MAAn5yR9IveLLpdrgQoIX6rLDODkXAh8sLrOSeTy3eFmt3KnE4g8M4CTc8FzOwqHyJn3hNL19L2o8QAI0/RHRMEBC+DkXAhzyniLhy6wwtjMUiW06WoGIkcUHDABTs4Fj5MbEBO5URibQT4UrQsOJ9cfIgoORIGTc8F0csKT8WYmcs1ePNbcJfrp7S29xU6myBEFly3AybkwcnK+jDeD7Tp1qszarquG0Do5ouAAN3ByLoycPPqsWcYbx4W3uG2rL7xRQ5iLHFFwwAQ4ORcm5+RJzngz/7jMerueKLBW5wMn50JIYcabX3QZXANnNdU9DZEDC+DkcyUJGW/U/tZQ4dH9rl6PEDmwAE4OgMOBkwPgcODkADgcODkADgdODoDDgZMD4HDg5AA4HDg5IYSEO87cqvtiuONMuheSPjTfk8Un5w4CTk4IIbfqvhi+sPhW3Rct2mnu6xD0X2HR3D3GFMtC+B63TsnpEHnXsfyakvyaY63R4+tVNdXeEflx0Ostya8pya8pyW+Mf2m4tVFb2XOxOlpTU5JfU1LVZTTZ9Sr1ULplyKXaO6LUKIvJcObHyf8/SMjb5xvHHHAAAAAASUVORK5CYII=" alt="" />

这个案例和前一篇文章的案例是一样的,我们修改的其实只是ApplicationContext.xml文件,其他代码不会变所以这里就不多做解释了。

直接给出ApplicationContext.xml代码。里面的注释好好看一下。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> -->
<!-- 引入peoperties文件 -->
<!-- <context:property-placeholder location="classpath:db.properties"/> -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties"/>
</bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
</bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean> <bean id="AccountDao" class="cn.itcast.dao.AccountDaoimpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
<bean id="AccountService" class="cn.itcast.service.AccountServiceimpl"> </bean>
<!-- 第一步:配置事务管理器 -->
<!-- 事务管理器
之前提过的。事务管理器针对不同的持久层有不同的类,比如Spring自带的SpringJdbc,Hibernata等等。这里用的
就是Sping自带的Jdbc,所以这里用的类是DataSourceTransactionManager
-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--
为什么要把dataSource交给transactionManager(事务管理器),
因为事务管理器,需要从数据源获取连接,才能开启事务,提交事务,回滚事务 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--第二步: 配置通知, -->
<!-- 需要通知(Advice),用来对事务增强 。其实advice代表的是环绕前,环绕后要干的事情,
环绕前,环绕后用来干嘛,不就是开启事务,提交事务吗?但是开启事务,提交事务由什么来完成呢?不就是
transactionManager来做。 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <!-- 接下来配事务的配置属性,为什么要配?这样的话,对什么方法,应用怎样的事务配置就知道了。这些配置信息就会成为TransactionDefinition对象
TransactionDefinition里面有什么还记得吗?
之前的论文提过的有四类:1.以ISOLATION开头的 ISOLATION_* :事务隔离级别
2.PROPAGATION_* 事务的传播行为等四个。 -->
<tx:attributes>
<!--
name 方法名
isolation 隔离级别
propagation 传播行为
timeout 超时时间
read-only 是否只读 (false代表可以更改,true的话代表不能更改) rollback-for 配置一些异常类型,发生这些异常 回滚事务。
no-rollback-for 配置一些异常类型,发生这些异常不 回滚事务。
如果没有配置上面两个,默认发生什么异常都要回滚,
-->
<tx:method name="transfer" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
</tx:attributes>
</tx:advice> <!-- 通知都有了接下来第三步就是配置切面了 -->
<aop:config>
<aop:advisor advice-ref="transactionAdvice" pointcut="execution(* cn.itcast.service.AccountServiceimpl.*(..) )"/> </aop:config> </beans>

执行结果:已经有事务的控制了。要不一起成功要不都不成功。

注意!注意!

Spring事务管理Advice,是基于Spring 传统AOP, 所以使用aop :advisor配置

27Spring_的事务管理_银行转账业务加上事务控制_基于tx.aop进行声明式事务管理的更多相关文章

  1. Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制

    Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制 201311.27 代码下载 链接: http://pan.baidu.com/s/1kYc6c 密码: 233t 前言 ...

  2. Spring事务的介绍,以及基于注解@Transactional的声明式事务

    前言 事务是一个非常重要的知识点,前面的文章已经有介绍了关于SpringAOP代理的实现过程:事务管理也是AOP的一个重要的功能. 事务的基本介绍 数据库事务特性: 原子性 一致性 隔离性 持久性 事 ...

  3. Spring AOP实现声明式事务代码分析

    众所周知,Spring的声明式事务是利用AOP手段实现的,所谓"深入一点,你会更快乐",本文试图给出相关代码分析. AOP联盟为增强定义了org.aopalliance.aop.A ...

  4. 实现自己的BeanFactory、AOP以及声明式事务

    实现自己的BeanFactory                                                                   在使用spring时,我们很少用& ...

  5. Spring注解驱动开发(四)-----aop、声明式事务

    AOP 概念 指在程序运行期间动态的将某段代码切入到指定方法指定位置进行运行的编程方式:-----基于动态代理 一个aop示例 1.导入aop模块:Spring AOP:(spring-aspects ...

  6. 28Spring_的事务管理_银行转账业务加上事务控制_基于注解进行声明式事务管理

    将applicationContext.xml 和 AccountServiceImpl 给备份一个取名为applicationContext2.xml 和 AccountServiceImpl2.j ...

  7. AOP:声明式事务管理流程

    1. 注册BeanFactoryTransactionAttributeSourceAdvisor @EnableTransactionManagement --> @Import(Transa ...

  8. 阶段3 2.Spring_10.Spring中事务控制_8 spring基于纯注解的声明式事务控制

    新建项目 把之前项目src下的内容全部复制过来 pom.xml内复制过来 开始配置 新建一个config的包,然后再新建配置文件类SpringConfiguration @Configuration这 ...

  9. 全面分析 Spring 的编程式事务管理及声明式事务管理

    开始之前 关于本教程 本教程将深入讲解 Spring 简单而强大的事务管理功能,包括编程式事务和声明式事务.通过对本教程的学习,您将能够理解 Spring 事务管理的本质,并灵活运用之. 先决条件 本 ...

随机推荐

  1. How to upgrade workflow assembly in MOSS 2007

    This problem generally start when you are having an existing custom workflow and there are instances ...

  2. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q85-Q87)

    Question 85You create a Microsoft .NET Framework console application that uses a Representational St ...

  3. ubuntu14.0安装arm-linux-gcc交叉编译环境

    1.下载文件: 安装包:arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz 下载地址  http://pan.baidu.com/s/1pJwQ6Sj 2.开始安装(建议大 ...

  4. Java或Android开发中,去掉块注释格式化后每行出现的星号(*)的解决方案。(Eclipse)

    找到子项,在 Window->Prefrences->Java->Code Style->Formatter,点击New新建 Active profile,然后在Comment ...

  5. 斯坦福iOS7公开课7-9笔记及演示Demo

    这一部分主要介绍了iOS的绘图.手势.协议.block.力学特效动画(包括重力.碰撞.吸附等)以及自动布局的内容. 1.绘图.手势 (1)调用一个自定义的UIView时,可以使用awakeFromNi ...

  6. iOS开发之网络编程--6、NSURLSessionConfiguration笔记

    NSURLSessionConfiguration对象用于初始化NSURLSession对象. 展开请求级别中与NSMutableURLRequest相关的可供选择的方案,我们可以看到NSURLSes ...

  7. Monyer's Game 11~15关过关方法

    到目前为止,玩这个小游戏并过关的人数已经达到了81人,首先Monyer要感谢各位的捧场与支持.继续上次的<Monyer's Game 6~10关过关方法>,我们来看剩下几关的过关方法. 但 ...

  8. Effective Java 18 Prefer interfaces to abstract classes

    Feature Interface Abstract class Defining a type that permits multiple implementations Y Y Permitted ...

  9. WP开发-Toolkit组件 列表采集器(ListPicker)的使用

    列表采集器ListPicker在作用上与html中的<select/>标签一样 都是提供多选一功能,区别在于ListPicker可以自定义下拉状态和非下拉状态的样式. 1.模板设置 Lis ...

  10. 大数据公益课堂成就你高薪之梦,30W,50W,100W...

    从之前的知道“大数据”这词,到2013年正式开始了解大数据领域,再到2014年深入研究大数据相关的领域,到现在逐渐影响周围的同学.朋友和家人.大数据技术将给我们带来的远不止我们想到的这些.曾经我身边的 ...