在网上找到的都是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.
分享到:
相关推荐
tx:advice和aop config的配置全部注释掉。 其余和切面、通知有关的配置都注释掉,或者删掉这个属性值引用前面定义的transactionManager bean添加保留 其余和切面、通知有关的配置都注释掉,或者删掉 这个属性值引用...
Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. 这个源码示例非常不错,包括所有的源码和jar包,下载后eclipse 或 myeclipse 导入就能用。 里面有详细的说明和注释,...
-- 配置事务管理器,這個事務性是爭對pdm數據庫的 --> <bean id="transactionManagerPdm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager " p:dataSource-ref="dataSourcePdm"/> ...
application.xml配置 <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=...
--配置事务管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!--配置事务的通知--> <tx:advice id="advice"> <tx:attributes> <tx:...
-- 配置那个类那个方法用到事务处理 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="add*" ...
-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> </property> <!-- 配置事务的传播特性 --> <tx:advice id=...
-- 创建事务管理器(spring针对hibernate实现的事务管理的切面类) --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <!-- 事务的通知类型 -...
-- 配置那个类那个方法用到事务处理 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="add*" ...
-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 配置事务通知属性 --> <tx:...
-- 配置那个类那个方法用到事务处理 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="add*" ...
三大框架分页的实现: DAO里写法: //查出页面要显示的字段 -----分页代码 页面上的查询全部 ... <property name="newsclassService"> //这个名字要和action里定义的那个成员变量对应 </bean>
-- JTA环境的事务配置 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager or WebLogicJtaTransactionManager"/> --> <!-- 使用annotation定义事务 --> <tx:...