Spring转账业务_注解配置事物控制
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转账业务_注解配置事物控制的更多相关文章
- Spring转账业务_XML配置事物控制
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring MVC4 纯注解配置教程
阅读本文需要又一定的sping基础,最起码要成功的运行过一个SpringMvc项目. 在传统的Spring项目中,我们要写一堆的XML文件.而这些XML文件格式要求又很严格,很不便于开发.而网上所谓的 ...
- Spring学习之旅(八)Spring 基于AspectJ注解配置的AOP编程工作原理初探
由小编的上篇博文可以一窥基于AspectJ注解配置的AOP编程实现. 本文一下未贴出的相关代码示例请关注小编的上篇博文<Spring学习之旅(七)基于XML配置与基于AspectJ注解配置的AO ...
- spring mvc 基于注解 配置默认 handlermapping
spring mvc 是类似于 Struts 的框架.他们都有一个最主要的功能就是URL路由.URL路由能将请求与响应请求处理逻辑的类(在Struts中即是action,在spring mvc 中即是 ...
- Spring IOC-基于注解配置的容器
Spring中提供了基于注解来配置bean的容器,即AnnotationConfigApplicationContext 1. 开始 先看看在Spring家族中,AnnotationConfigApp ...
- 采用spring的schedule注解配置定时任务
1 在springmvc配置文件中新增以下配置 <!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 --> <task:scheduled-tasks s ...
- Spring事务_注解_特性
Spring 是一个 IOC 和 AOP 容器框架. ## 控制反转(IOC) ## 传统的 java 开发模式中,当需要一个对象时,我们会自己使用 new 或者 getInstance 等直接或者间 ...
- Spring中 使用注解+c3p0+事物 《模拟银行转账》
使用注解的方式 模拟转账 要么都成功 要么都失败 !保持一致性! 准备工作: jar包: 需要的类: UserDao: package com.hxzy.spring.c3p0.Dao ...
- Spring MVC 全注解配置 (十一)
完整的项目案例: springmvc.zip 目录 实例 项目结构: 父级的pom配置: <?xml version="1.0" encoding="UTF-8&q ...
随机推荐
- Python基础(17)_面向对象程序设计(抽象类、继承原理、封装、多态,绑定方法)
一.抽象类 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化 1.在python中实现抽象类 import abc #利用abc模块实现抽象类 class All_file(metacl ...
- 解决远程桌面关闭后teamviewer不能连接的问题
使用windows远程桌面连接远程电脑,在关闭远程桌面后,windows系统会锁定,此时再用teamviewer连接会出现“无法捕捉画面”或者“拒绝连接”的问题. 解决办法:设置要连接的远程电脑上的t ...
- HAProxy详解
HAProxy概述与配置 一.HAProxy概述 HAProxy是由 WillyTarreau开发的一款具备高可用性.负载均及基于 TCP和 HTTP的应用代理开源软件,基于HAProxy的负载均衡架 ...
- GitHub命名规则
● Added ( 新加入的需求 ) ● Fixed ( 修复 bug ) ● Changed ( 完成的任务 ) ● Updated ( 完成的任务,或者由于第三方模块变化而做的变化 )
- Linux系统资源查询命令(cpu、io、mem)
cpu/mem: 1. 指定pid top -p pid1,pid2,... 2. top排序 先top,然后 输入大写P,则结果按CPU占用降序排序.输入大写M,结果按内存占用降序排序. io: ...
- 【HackerRank】 Chocolate Feast
Little Bob loves chocolates, and goes to the store with $N money in his pocket. The price of each ch ...
- ES6 随记(2)-- 解构赋值
上一章请见: 1. ES6 随记(1)-- let 与 const 3. 解构赋值 a. 数组的解构赋值 let [a1, b1, c1] = [1, 2, 3]; console.log(a1, b ...
- jQuery图片下滑切换焦点图
在线演示 本地下载
- Python 数值类型
1.数值类型分为整形(二进制(0b),八进制(0o),十进制,十六进制(0x) ),浮点型,long,complex(复合行) 当我们说十进制数的时候,是逢10进1,就是说到达10的时候就要向前一位进 ...
- java resources 红叉 An error occurred while filtering resources
用eclipse创建了一个Spring mvc的Maven项目,在项目上有个叉叉,通过Window -> Show View -> Markers中看到错误原因 An error occu ...