spring.net tx:advice 和 aop:config 配置事务 匹配名字的方法管理事务
在网上找到的都是java里的配置方式,后来认真读了下spring.net的帮助文档,解决了这个问题:现在把我的server层的配置文件copy出来:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:aop = "http://www.springframework.net/aop"
xmlns:tx="http://www.springframework.net/tx">
<!--fun list-->
<object id="userFunServer" type="com.elitel.im.bl.system.impl.UserFunImpl, com.elitel.im.bl">
<property name="UserDao" ref="userDao"/>
</object>
<!--自定义驱动方式(根据方法的名字判断事务的类型)-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics...-->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="Get*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="Do*"/>
</tx:attributes>
</tx:advice>
<object id="serviceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="pattern" value="com.elitel.im.bl.*"/>
</object>
<aop:config>
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
</aop:config>
</objects>
主要是<property name="pattern" value="com.elitel.im.bl.*"/>节点的配置,表示匹配com.elitel.im.bl下所有的类及方法。
我把spring.net的帮助文档里相关的部分也copy出来:
You can also define the transactional semantics you want to apply through the use of a <tx:advice> definition. This lets you define the transaction metadata such as propagation and isolation level as well as the methods for which that metadata applies external to the code unlike the case of using the transaction attribute. The <tx:advice> definition creates an instance of a ITransactionAttributeSource during parsing time. Switching to use <tx:advice> instead of <tx:attribute-driven/> in the example would look like the following
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="Save*"/>
<tx:method name="Delete*"/>
</tx:attributes>
</tx:advice>
This says that all methods that start with Save and Delete would have associated with them the default settings of transaction metadata. These default values are listed below..
Here is an example using other elements of the <tx:method/> definition
<!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> object below) -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="Get*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
The <tx:advice/> definition reads as “... all methods on starting with 'Get' are to execute in the context of a read-only transaction, and all other methods are to execute with the default transaction semantics”. The 'transaction-manager' attribute of the <tx:advice/> tag is set to the name of the PlatformTransactionManager object that is going to actually drive the transactions (in this case the 'transactionManager' object).
You can also use the AOP namespace <aop:advisor> element to tie together a pointcut and the above defined advice as shown below.
<object id="serviceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="pattern" value="Spring.TxQuickStart.Services.*"/>
</object> <aop:config> <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/> </aop:config>
This is assuming that the service layer class, TestObjectManager, in the namespace Spring.TxQuickStart.Services. The <aop:config/> definition ensures that the transactional advice defined by the 'txAdvice' object actually executes at the appropriate points in the program. First we define a pointcut that matches any operation defined on classes in the Spring.TxQuickStart.Services (you can be more selective in your regular expression). Then we associate the pointcut with the 'txAdvice' using an advisor. In the example, the result indicates that at the execution of a 'SaveTwoTestObjects' and 'DeleteTwoTestObject', the advice defined by 'txAdvice' will be run.
spring.net tx:advice 和 aop:config 配置事务 匹配名字的方法管理事务的更多相关文章
- spring tx:advice 和 aop:config 配置事务
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- [转]spring tx:advice 和 aop:config 配置事务
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www. ...
- spring中<tx:advice></tx:advice>是什么意思
<tx:advice id="tv" transaction-manager="transactionManager"> <tx:attrib ...
- [转]spring中<tx:advice></tx:advice>意义
<tx:advice id="tv" transaction-manager="transactionManager"> <tx:attrib ...
- Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...
- 【系统Configmachine.config与自己的应用程序的App.config/Web.Config配置节点重复】解决方法
自己的应用程序的App.config或Web.Config文件中与系统的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Configmachine.co ...
- spring声明式事务 同一类内方法调用事务失效(转)
原文 https://blog.csdn.net/jiesa/article/details/53438342 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- spring声明式事务 同一类内方法调用事务失效
只要避开Spring目前的AOP实现上的限制,要么都声明要事务,要么分开成两个类,要么直接在方法里使用编程式事务 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- Spring Cloud(十四)Config 配置中心与客户端的使用与详细
前言 在上一篇 文章 中我们直接用了本应在本文中配置的Config Server,对Config也有了一个基本的认识,即 Spring Cloud Config 是一种用来动态获取Git.SVN.本地 ...
随机推荐
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- Linux系统安装时分区的选择(推荐)
Linux系统安装时分区的选择(推荐) 出处:http://www.cnblogs.com/gylei/archive/2011/12/04/2275987.html 前言: 以前初识Linux时, ...
- Does the OpenSceneGraph have a native file format?
From OpenSceneGraph-3.0 onwards we have new native file formats based on generic serializers that ar ...
- Android笔记:ninepatch
上边框和左边框绘制的部分就表示当图片需要拉伸时就拉伸黑点标记的区域 下边框和右边框绘制的部分则表示内容会被放置的区域
- iOS - UIButton设置图片文字上图下文排列
经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButton ...
- 资源监控工具--spotlight
1.被监控服务器为Ubuntu server,先在服务器上创建一个用户,专门用于监控使用! 因为远程监控服务器,需要获取服务器的资源,所以必须要有权限.使用文档明确说明,不能使用root用户,但是我用 ...
- Delphi函数参数传递 默认参数(传值)、var(穿址)、out(输出)、const(常数)四类
Delphi的参数可以分为:默认参数(传值).var(传址).out(输出).const(常数)四类 可以对比C/C++的相关知识,类比学习. 1.默认参数是传值,不会被改变,例子 function ...
- SQL脚本书写的几点建议
1.索引很关键,创建合理的索引,提升查询速度: DBCC FREEPORCCACHE DBCC DROPCLEANBUFFERS ...
- 【JAVA集合框架之List与Set】
一.概述 JAVA的集合框架中定义了一系列的类,这些类都是存储数据的容器.与数组.StringBuffer(StringBuilder)相比,它的特点是: 1.用于存储对象. 2.集合长度可变. 3. ...
- 声明replicated属性之后我编译不通过的问题