1、beans.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: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/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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 扫描包基础目录 -->
<context:component-scan base-package="com.wisezone"></context:component-scan> <!-- 加载properties 配置文件 -->
<context:property-placeholder location="db.properties"/> <!-- c3p0数据源配置 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean> <!-- jdbc模板类配置 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<!-- 属性名称固定 -->
<property name="dataSource" ref="dataSource"></property>
</bean> 37 <aop:aspectj-autoproxy/>
38
39 <!-- 事物管理器配置 -->
40 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
41 <property name="dataSource" ref="dataSource"></property>
42 </bean>
43
44 <tx:annotation-driven transaction-manager="txManager"/> </beans>
 package com.wisezone.service.impl;

 import javax.annotation.Resource;

 import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import com.wisezone.dao.AccountDao;
import com.wisezone.service.AccountService; @Service
public class AccountServiceImpl implements AccountService { @Resource
private AccountDao accountDao; @Override
@Transactional(propagation=Propagation.REQUIRED)
public int updateAccountByTranfer(int yuanAid, int muBiaoAid, double money) { int result = 0;
int r1 = accountDao.outAccount(yuanAid, money);//出账
int a = 1/0;
int r2 = accountDao.inAccount(muBiaoAid, money);//入账 if (r1 > 0 && r2 > 0) {
result = 1;
} return result;
} }

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. 前端 JS&&DOM续

    JS续 1.序列化 JSON.stringify(obj)   序列化 JSON.parse(str)        反序列化 2.转义 decodeURI( )                   ...

  2. PAT 天梯赛 L1-033. 出生年 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-033 AC代码 #include <cstdio> #include <cstring> ...

  3. 每天一个Linux命令(50)netstat命令

        netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况.     (1)用法:     用法:  netstat [选项参数]     (2)功能: ...

  4. Python编程-多进程二

    7.进程间通信(IPC)方式二:管道 (1)创建管道的类: Pipe([duplex]):在进程之间创建一条管道,并返回元组(conn1,conn2),其中conn1,conn2表示管道两端的连接对象 ...

  5. 基于SSM的单点登陆01

    使用SSM的Maven聚合项目 建立父项目market的pom文件 <?xml version="1.0" encoding="UTF-8"?> & ...

  6. HTML如何禁止文本框输入

    禁止文本框输入有以下两种方法: 1,设置input为只读状态,代码如下: <input readonly="readonly" value="test1" ...

  7. PHP封装时间类

    开发中经常用到时间的一些操作,比如昨天,今天,前天,近七天,一周等等. class time{ private $year;//年 private $month;//月 private $day;// ...

  8. PHP的异常处理、错误的抛出及错误回调函数

    一.错误.异常和等级常量表 error:不能再编译期发现运行期的错误,不如试图echo输出一个未赋值的变量,这类问题往往导致程序或逻辑无法继续下去而需要中断. exception:程序执行过程中出现意 ...

  9. 斯坦福机器学习视频笔记 Week6 关于机器学习的建议 Advice for Applying Machine Learning

    我们将学习如何系统地提升机器学习算法,告诉你学习算法何时做得不好,并描述如何'调试'你的学习算法和提高其性能的“最佳实践”.要优化机器学习算法,需要先了解可以在哪里做最大的改进. 我们将讨论如何理解具 ...

  10. MongoDB快速入门(四)- 插入文档

    插入文档 将数据插入到MongoDB集合,需要使用MongoDB 的 insert() 方法. 语法 insert()命令的基本语法如下: >db.COLLECTION_NAME.insert( ...