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. MySQL数据库(3)_MySQL数据库表记录操作语句

    附: MYSQL5.7版本sql_mode=only_full_group_by问题 .查询当前sql_mode: select @@sql_mode .查询出来的值为: set @@sql_mode ...

  2. Django 补充models操作,中间件, 缓存,信号,分页

    1.Model 一对多 补充 models如下: class UserType(models.Model): caption = models.CharField(max_length=16) cla ...

  3. ES集群性能调优链接汇总

    1. 集群稳定性的一些问题(一定量数据后集群变得迟钝) https://elasticsearch.cn/question/84 2. ELK 性能(2) — 如何在大业务量下保持 Elasticse ...

  4. grads 读取shp

    自从GrADS2.0.a8版本开始,GrADS引入了对shp图形的支持,关于此格式在这里不多说, 于是今晚就简单测试了一下最简单画图和查询命令(后续还将测试输出shp图形的命令)    测试数据采用的 ...

  5. pagination结合ajax

    function getContent(page,Id){ $.ajax({ type:'get', url:'www.baidu.com', dataType:'jsonp', data:{ }, ...

  6. h => h(App)解析

    在创建Vue实例时经常看见render: h => h(App)的语句,现做出如下解析: h即为createElement,将h作为createElement的别名是Vue生态系统的通用管理,也 ...

  7. 51nod 1009 数字1的数量 数位dp

    1009 数字1的数量 基准时间限制:1 秒 空间限制:131072 KB   给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数.   例如:n = 12,包含了5个1 ...

  8. 刻录DVD.XP系统盘(U盘)

    ZC:用这个软件,安装太慢了... 忽然发现 以前有别的软件可以使用:http://www.cnblogs.com/vmskill/p/6196522.html 1.我是在这个论坛看到 这个工具的:h ...

  9. How to use the ZooKeeper driver for ServiceGroup in OpenStack Nova

    ServiceGroup APIs Nova会从ServiceGroup API 中查询节点的存活信息. ServiceGroup API 工作流程是: 当一个compute worker (runn ...

  10. 根据图片名字在drawable中得到图片

    int imageId = context.getResources().getIdentifier("图片的名字","drawable", "包名& ...