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 ...
随机推荐
- Protobuf支持 pointf
Protobuf支持 pointf序列化 加入:ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(System.Drawing.PointF), fa ...
- Andorid:日常学习笔记(3)——掌握日志工具的使用
Andorid:日常学习笔记(3)——掌握日志工具的使用 使用Android的日志工具Log 方法: Android中的日志工具类为Log,这个类提供了如下方法来供我们打印日志: 使用方法: Log. ...
- SpringMVC:学习笔记(4)——处理模型数据
SpringMVC—处理模型数据 说明 SpringMVC 提供了以下几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体即可通过该对象添 ...
- C# 调用VS自带程序WebDev.WebServer40.EXE 源代码
通过Process.Start启动,VS自带程序WebDev.WebServer40.EXE 在内网架设网站时,为安装IIS条件下用VS自带的小程序来测试效果非常不错! using System; u ...
- JQuery Div层滚动条控制(模拟横向滚动条在最顶端显示)
想让DIV层滚动条显示在顶端,CSS样式没找到相关属性,于是用2个DIV层来模拟做了一个.经测试IE浏览器上显示并不太美观!不知道是否还有更好的办法可以实现这功能呢? aaaaaaasssssss ...
- UI组件之UIImage
UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...
- Dubbo框架入门介绍
背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 当网站流量很小时,只需一个 ...
- CSS3 画点好玩的东西
虽然项目赶工还是挺忙的,但闲了总要找点乐子嘛,毕竟秃顶和猝死两座大山夹逼着编程员们. 好吧,其实是无聊起来我自己都怕,于是就做了点小玩意. .heart { position: relative; t ...
- Docker容器技术-镜像分发
一.镜像分发 1.镜像及镜像库的命名方式 指定镜像名称和标签的方法: 在狗偶见镜像时 通过docker tag命令 [root@bogon ~]# cd identidock/ [root@bogon ...
- Python编程-模块和包
一.模块 1.什么是模块? 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 2.为何要使用模块? 如果你退出python解释器然后重新进入,那么你之前定义的函 ...