Spring AOP (事务管理)
一、声明式事务管理的概括
二、在配置文件中配置事务管理
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.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx.xsd 14 http://www.springframework.org/schema/aop 15 http://www.springframework.org/schema/aop/spring-aop.xsd"> 16 17 <!-- 注册数据源:C3P0数据源 --> 18 <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 19 <property name="driverClass" value="${jdbc.driverClass}" /> 20 <property name="jdbcUrl" value="${jdbc.url}" /> 21 <property name="user" value="${jdbc.user}" /> 22 <property name="password" value="${jdbc.password}" /> 23 </bean> 24 25 <!-- 注册JDBC属性文件 --> 26 <context:property-placeholder location="classpath:jdbc.properties"/> 27 28 <!-- 注册Dao --> 29 <bean id="accountDao" class="com.tongji.dao.AccountDaoImpl"> 30 <property name="dataSource" ref="myDataSource"/> 31 </bean> 32 <bean id="stockDao" class="com.tongji.dao.StockDaoImpl"> 33 <property name="dataSource" ref="myDataSource"/> 34 </bean> 35 <!-- 注册Service --> 36 <bean id="stockService" class="com.tongji.service.StockProcessServiceImpl"> 37 <property name="accountDao" ref="accountDao"/> 38 <property name="stockDao" ref="stockDao"/> 39 </bean> 40 41 <!-- 事务 --> 42 <!-- 注册事务管理器 --> 43 <bean id="myTxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 44 <property name="dataSource" ref="myDataSource"/> 45 </bean> 46 <!-- 注册事务通知 --> 47 <tx:advice id="txAdvice" transaction-manager="myTxManager"> 48 <tx:attributes> 49 <!-- 指定在连接点方法上应用的事务属性 --> 50 <tx:method name="open*" isolation="DEFAULT" propagation="REQUIRED"/> 51 <tx:method name="buyStock" isolation="DEFAULT" propagation="REQUIRED" rollback-for="StockException"/> 52 </tx:attributes> 53 </tx:advice> 54 55 <!-- AOP配置 --> 56 <aop:config> 57 <!-- 指定切入点 --> 58 <aop:pointcut expression="execution(* *..service.*.*(..))" id="stockPointCut"/> 59 <aop:advisor advice-ref="txAdvice" pointcut-ref="stockPointCut"/> 60 </aop:config> 61 </beans>
转载于:https://www.cnblogs.com/zq-boke/p/8515505.html
Spring AOP (事务管理)相关推荐
- Spring AOP事务管理(使用切面把事务管理起来)
在<Spring Transaction 分析事务属性(事务的基本概念.配置)>基础上 1.使用基于注解的AOP事务管理 <tx:annotation-driven transac ...
- Spring ORM示例 - 带有AOP事务管理
Spring ORM示例 - 带有AOP事务管理 这是一个非常简单的Spring ORM示例,向您展示如何使用Spring配置应用程序 依赖注入(@Autowired annotation), JPA ...
- Spring AOP事务实现原理之事务管理器TransactionManager
流程图 该图介绍了事务的传播行为 该流通图展示的是TransactionManager具体如何结合事务的传播行为进行事务获取 该流通图展示的是TransactionManager具体如何结合事务的传播 ...
- 使用动态代理简单模拟一下spring的事务管理
按照平时写代码的习惯,我们会定义一个service接口 package com.proxy.test; public interface UserService {public void sayHel ...
- java 自定义异常 未回滚_抛出自定义异常,spring AOP事务不回滚的解决方案
spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...
- 哪些方法不能够实施Spring AOP事务
2019独角兽企业重金招聘Python工程师标准>>> 哪些方法不能够实施Spring AOP事务 由于Spring事务管理是基于接口代理或动态字节码技术.通过AOP实施事务增强. ...
- Spring的事务管理难点剖析:应用分层的迷惑
2019独角兽企业重金招聘Python工程师标准>>> Web.Service及DAO三层划分就像西方国家的立法.行政.司法三权分立一样被奉为金 科玉律,甚至有的开发人员认为如果要使 ...
- Spring JDBC-实施Spring AOP事务注意事项及案例分析
实施SpringAOP事务注意事项 基于接口动态代理的AOP事务增强 基于CGLib字节码动态代理的AOP事务增强 示例 特别说明 示例源码 实施SpringAOP事务注意事项 众所周知,Spring ...
- spring教程--事务管理
Spring的事务管理 1.1 事务: 事务:是逻辑上一组操作,要么全都成功,要么全都失败. 事务特性: ACID: 原子性:事务不可分割 一致性:事务执行的前后,数据完整性保持一致. 隔离性:一个事 ...
- batch spring 重复执行_一个3年老javaer竟然连Spring的事务管理都不知道,惊呆了
1.事务介绍 事务(Transaction),一般是指要做的或所做的事情.在计算机术语中是指访问并可能更新数据库中各种数据项的一个程序执行单元(unit). 这里我们以取钱的例子来讲解:比如你去ATM ...
最新文章
- 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫
- DataTable转换成IList
- IhttpHandler
- ListActivity的使用
- html登录注册的正则,怎么用html5编写用户注册验证程序
- Angular CLI 全局 ng.cmd 文件内容分析
- src与href属性的区别
- Spring Mvc 整合 Mybatis
- Windows Phone 项目实战之我的微盘
- abs内控流程图_abs成本费用核算流程图
- 豆瓣评分预测(如何用自己的数据集进行文本分类)——基于pytorch的 BERT中文文本分类,超详细教程必会!!!
- Chrome、FireFox浏览器新标签页打开搜索和书签
- Excel怎么合并单元格
- Linux进程管理命令之accton/lastcomm
- 脚本启动shipyard
- 由标明空子树的先序遍历序列创建二叉树
- 用C语言/C++实现一个基础的电话簿
- 腾讯QQ屏幕识图工具,对开发用处很多,特别对于需要图片文字识别的
- hdu 4433 locker(DP)
- 实时语音驱动实现Android端Avatar虚拟人表情表达
热门文章
- HTTP 200 OK和HTTP 304 Not modified的由来
- java vo转map_Jython:在 Java 程序里运行 Python 代码 4.5
- java的应用程序开发_开发一个Java应用程序(1)
- python3读写excel文件_Python读写/追加excel文件Demo
- logo自动旋转 html,HTML/CSS3 Logo选择器
- 用C语言写HMI程序,HMI画面元素组成设计及代码生成方法与流程
- 什么情况下选择linux,在哪种情况下建议选择BSD系统而不是Linux?
- python 3d大数据可视化软件_最受欢迎的大数据可视化软件
- 最简单的卸载vrv方法_低端赤道仪粗对极轴最简单方法
- 今年电子设计竞赛取消了?