[转]spring tx:advice 和 aop:config 配置事务
- <?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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
- >
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate3.HibernateTransactionManager"
- abstract="false" lazy-init="default" autowire="default"
- dependency-check="default">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- </property>
- </bean>
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="add*" propagation="REQUIRED" />
- <tx:method name="delete*" propagation="REQUIRED" />
- <tx:method name="update*" propagation="REQUIRED" />
- <tx:method name="add*" propagation="REQUIRED" />
- <!-- <tx:method name="*" propagation="true" />-->
- </tx:attributes>
- </tx:advice>
- <aop:config>
- <aop:pointcut id="allManagerMethod"
- expression="execution(* com.service.*.*(..))" />
- <aop:advisor advice-ref="txAdvice"
- pointcut-ref="allManagerMethod" />
- </aop:config>
- </beans>
Eclipse不能识别<tx:advice/>标签
在开发Spring的过程中,有时会出现Eclipse不能识别<tx:advice/>标签。
提示出现以下错误:
The prefix "tx" for element "tx:advice" is not bound
这个错误的原因很简单是:
我们在定义申明AOP的时候。。没有加载schema。
具体表现如下:
- <beans>
- <tx:advice
id="txAdvice"
transaction-manager="transactionManager"> - <tx:attributes>
- <tx:method
name="get*"
read-only="true"/> - <tx:method
name="*"
propagation="REQUIRES_NEW"
rollback-for="Exception"/> - </tx:attributes>
- </tx:advice>
- <!-- aop代理设置-->
- <aop:config
proxy-target-class="true"> - </aop:config>
- </beans>
这时会抛出异常不认<TX>标签。。起先还以为是没有加载JAR包呢。。
后来读AOP文档才发现<beans>中要加入“xmlns:aop”的命名申明,并在“xsi:schemaLocation”中指定aop配置的schema的地址
配置文件如下:
- <?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: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.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
- >
这些才是最关键的地方。。后面的配置不变。。。。
Spring使用 <tx:advice>和 <aop:config> 用来配置事务,具体如何配置你可以参考Spring文档。
综上:包com.evan.crm.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法
<tx:advice/> 有关的设置
这一节里将描述通过 <tx:advice/> 标签来指定不同的事务性设置。默认的 <tx:advice/> 设置如下:
事务传播设置是 REQUIRED
隔离级别是 DEFAULT
事务是 读/写
事务超时默认是依赖于事务系统的,或者事务超时没有被支持。
任何 RuntimeException 将触发事务回滚,但是任何 checked Exception 将不触发事务回滚
这些默认的设置当然也是可以被改变的。 <tx:advice/> 和 <tx:attributes/> 标签里的 <tx:method/> 各种属性设置总结如下:
表 9.1. <tx:method/> 有关的设置
| 属性 | 是否需要? | 默认值 | 描述 |
| name | 是 | 与事务属性关联的方法名。通配符(*)可以用来指定一批关联到相同的事务属性的方法。 如:'get*'、'handle*'、'on*Event'等等。 | |
| propagation | 不 | REQUIRED | 事务传播行为 |
| isolation | 不 | DEFAULT | 事务隔离级别 |
| timeout | 不 | -1 | 事务超时的时间(以秒为单位) |
| read-only | 不 | false | 事务是否只读? |
| rollback-for | 不 | 将被触发进行回滚的 Exception(s);以逗号分开。 如:'com.foo.MyBusinessException,ServletException' | |
| no-rollback-for | 不 | 不 被触发进行回滚的 Exception(s);以逗号分开。 如:'com.foo.MyBusinessException |
[转]spring tx:advice 和 aop:config 配置事务的更多相关文章
- spring tx:advice 和 aop:config 配置事务
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- spring.net tx:advice 和 aop:config 配置事务 匹配名字的方法管理事务
在网上找到的都是java里的配置方式,后来认真读了下spring.net的帮助文档,解决了这个问题:现在把我的server层的配置文件copy出来: <?xml version="1. ...
- spring cloud 2.x版本 Config配置中心教程
前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的文章eureka-server的实现. 参考 eureka-server ...
- Spring Boot 中使用 @Transactional 注解配置事务管理
事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...
- Spring Boot中使用@Transactional注解配置事务管理
事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...
- spring aop方式配置事务中的三个概念 pointcut advice advisor
AOP的3个关键概念 因为AOP的概念难于理解,所以在前面首先对Java动态代理机制进行了一下讲解,从而使读者能够循序渐进地来理解AOP的思想. 学习AOP,关键在于理解AOP的思想,能够使用AOP. ...
- spring tx:advice事务配置
http://blog.csdn.net/bao19901210/article/details/17226439 http://blog.csdn.net/rong_wz/article/detai ...
- Spring配置事务 http://www.cnblogs.com/leiOOlei/p/3725911.html
http://www.cnblogs.com/leiOOlei/p/3725911.html JNDI方式配置数据源: <?xml version="1.0" encodin ...
- Spring声明式事务(xml配置事务方式)
Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...
随机推荐
- 【Python学习笔记】使用Python计算皮尔逊相关系数
源代码不记得是哪里获取的了,侵删.此处博客仅作为自己笔记学习. def multipl(a,b): sumofab=0.0 for i in range(len(a)): temp=a[i]*b[i] ...
- 一种面向云服务的UCON多义务访问控制方法及系统
)设置每一云服务的义务项:建立每一云服务所包含的义务图:2)根据用户所请求的云服务查找该云服务的所有强制义务图和可选义务图,并提取该用户对该云服务的历史完成情况:3)对每一强制义务图,监控其每一义务项 ...
- 看jquery3.3.1学js类型判断的技巧
需要预习:call , typeof, js数据类型 1. isFunction中typeof的不靠谱 源码: var isFunction = function isFunction( obj ) ...
- javascript反混淆之packed混淆
function getKey() { var aaaafun = function(p, a, c, k, e, d) { e = function(c) { return (c < a ? ...
- JS中类型检测方式
在js中的类型检测目前我所知道的是三种方式,分别有它们的应用场景: 1.typeof:主要用于检测基本类型. typeof undefined;//=> undefined typeof 'a' ...
- Hadoop-MR[会用]MR程序的运行模式
1.简介 现在很少用到使用MR计算框架来实现功能,通常的做法是使用hive等工具辅助完成.但是对于其底层MR的原理还是有必要做一些了解. 2.MR客户端程序实现套路 这一小节总结归纳编写mr客户端程序 ...
- [How to]如何通过xib来自定义UIViewController
代码:https://github.com/xufeng79x/CreateControllerByXib 1.简介 UIViewController实例可以通过代码.storyborad或者xib方 ...
- Vim常用命令(转)—默写版
1.光标移动 上: 下: 左: 『字母小写』 右: 上一行行首: 『减号』 下一行行首: 行首: 『数字0』 行尾: 单词词尾或后一个单词词尾: 后一个单词词首: 单词词首或前一个单词词首: 跳转到特 ...
- maven添加jar包到本地仓库
mvn install:install-file -Dfile=desutill.jar -DgroupId=com.bfd -DartifactId=des -Dversion=1.0 -Dpack ...
- LeetCode解题报告—— Unique Binary Search Trees & Binary Tree Level Order Traversal & Binary Tree Zigzag Level Order Traversal
1. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that ...