1、beans.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="
  8. http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  12. http://www.springframework.org/schema/aop
  13. http://www.springframework.org/schema/aop/spring-aop.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  16.  
  17. <!-- 扫描包基础目录 -->
  18. <context:component-scan base-package="com.wisezone"></context:component-scan>
  19.  
  20. <!-- 加载properties 配置文件 -->
  21. <context:property-placeholder location="db.properties"/>
  22.  
  23. <!-- c3p0数据源配置 -->
  24. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  25. <property name="driverClass" value="${driver}"></property>
  26. <property name="jdbcUrl" value="${url}"></property>
  27. <property name="user" value="${user}"></property>
  28. <property name="password" value="${password}"></property>
  29. </bean>
  30.  
  31. <!-- jdbc模板类配置 -->
  32. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  33. <!-- 属性名称固定 -->
  34. <property name="dataSource" ref="dataSource"></property>
  35. </bean>
  36.  
  37. 37 <aop:aspectj-autoproxy/>
  38. 38
  39. 39 <!-- 事物管理器配置 -->
  40. 40 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  41. 41 <property name="dataSource" ref="dataSource"></property>
  42. 42 </bean>
  43. 43
  44. 44 <tx:annotation-driven transaction-manager="txManager"/>
  45.  
  46. </beans>
  1. package com.wisezone.service.impl;
  2.  
  3. import javax.annotation.Resource;
  4.  
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Propagation;
  7. import org.springframework.transaction.annotation.Transactional;
  8.  
  9. import com.wisezone.dao.AccountDao;
  10. import com.wisezone.service.AccountService;
  11.  
  12. @Service
  13. public class AccountServiceImpl implements AccountService {
  14.  
  15. @Resource
  16. private AccountDao accountDao;
  17.  
  18. @Override
  19. @Transactional(propagation=Propagation.REQUIRED)
  20. public int updateAccountByTranfer(int yuanAid, int muBiaoAid, double money) {
  21.  
  22. int result = 0;
  23. int r1 = accountDao.outAccount(yuanAid, money);//出账
  24. int a = 1/0;
  25. int r2 = accountDao.inAccount(muBiaoAid, money);//入账
  26.  
  27. if (r1 > 0 && r2 > 0) {
  28. result = 1;
  29. }
  30.  
  31. return result;
  32. }
  33.  
  34. }

Spring转账业务_注解配置事物控制的更多相关文章

  1. Spring转账业务_XML配置事物控制

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. Spring MVC4 纯注解配置教程

    阅读本文需要又一定的sping基础,最起码要成功的运行过一个SpringMvc项目. 在传统的Spring项目中,我们要写一堆的XML文件.而这些XML文件格式要求又很严格,很不便于开发.而网上所谓的 ...

  3. Spring学习之旅(八)Spring 基于AspectJ注解配置的AOP编程工作原理初探

    由小编的上篇博文可以一窥基于AspectJ注解配置的AOP编程实现. 本文一下未贴出的相关代码示例请关注小编的上篇博文<Spring学习之旅(七)基于XML配置与基于AspectJ注解配置的AO ...

  4. spring mvc 基于注解 配置默认 handlermapping

    spring mvc 是类似于 Struts 的框架.他们都有一个最主要的功能就是URL路由.URL路由能将请求与响应请求处理逻辑的类(在Struts中即是action,在spring mvc 中即是 ...

  5. Spring IOC-基于注解配置的容器

    Spring中提供了基于注解来配置bean的容器,即AnnotationConfigApplicationContext 1. 开始 先看看在Spring家族中,AnnotationConfigApp ...

  6. 采用spring的schedule注解配置定时任务

    1 在springmvc配置文件中新增以下配置 <!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 --> <task:scheduled-tasks s ...

  7. Spring事务_注解_特性

    Spring 是一个 IOC 和 AOP 容器框架. ## 控制反转(IOC) ## 传统的 java 开发模式中,当需要一个对象时,我们会自己使用 new 或者 getInstance 等直接或者间 ...

  8. Spring中 使用注解+c3p0+事物 《模拟银行转账》

    使用注解的方式  模拟转账 要么都成功 要么都失败 !保持一致性! 准备工作: jar包:  需要的类:       UserDao: package com.hxzy.spring.c3p0.Dao ...

  9. Spring MVC 全注解配置 (十一)

    完整的项目案例: springmvc.zip 目录 实例 项目结构: 父级的pom配置: <?xml version="1.0" encoding="UTF-8&q ...

随机推荐

  1. Python基础(17)_面向对象程序设计(抽象类、继承原理、封装、多态,绑定方法)

    一.抽象类 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化 1.在python中实现抽象类 import abc #利用abc模块实现抽象类 class All_file(metacl ...

  2. 解决远程桌面关闭后teamviewer不能连接的问题

    使用windows远程桌面连接远程电脑,在关闭远程桌面后,windows系统会锁定,此时再用teamviewer连接会出现“无法捕捉画面”或者“拒绝连接”的问题. 解决办法:设置要连接的远程电脑上的t ...

  3. HAProxy详解

    HAProxy概述与配置 一.HAProxy概述 HAProxy是由 WillyTarreau开发的一款具备高可用性.负载均及基于 TCP和 HTTP的应用代理开源软件,基于HAProxy的负载均衡架 ...

  4. GitHub命名规则

    ● Added ( 新加入的需求 ) ● Fixed ( 修复 bug ) ● Changed ( 完成的任务 ) ● Updated ( 完成的任务,或者由于第三方模块变化而做的变化 )

  5. Linux系统资源查询命令(cpu、io、mem)

    cpu/mem: 1. 指定pid top -p pid1,pid2,... 2. top排序 先top,然后  输入大写P,则结果按CPU占用降序排序.输入大写M,结果按内存占用降序排序. io: ...

  6. 【HackerRank】 Chocolate Feast

    Little Bob loves chocolates, and goes to the store with $N money in his pocket. The price of each ch ...

  7. ES6 随记(2)-- 解构赋值

    上一章请见: 1. ES6 随记(1)-- let 与 const 3. 解构赋值 a. 数组的解构赋值 let [a1, b1, c1] = [1, 2, 3]; console.log(a1, b ...

  8. jQuery图片下滑切换焦点图

    在线演示 本地下载

  9. Python 数值类型

    1.数值类型分为整形(二进制(0b),八进制(0o),十进制,十六进制(0x) ),浮点型,long,complex(复合行) 当我们说十进制数的时候,是逢10进1,就是说到达10的时候就要向前一位进 ...

  10. java resources 红叉 An error occurred while filtering resources

    用eclipse创建了一个Spring mvc的Maven项目,在项目上有个叉叉,通过Window -> Show View -> Markers中看到错误原因 An error occu ...