您的位置:首页 > 编程语言 > ASP

ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 使用AOP执行事务处理

2013-02-17 13:55 483 查看
方法一:

<object id="ServiceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="patterns">
<list>
<value>LMJ.Service.AdminService.UpdateAdmin</value>
</list>
</property>
</object>
<tx:advice id="txAdvice" transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="*" rollback-for="errorException" isolation="ReadCommitted" timeout="60"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut-ref="ServiceOperation" />
</aop:config>


方法二:

<object id="aroundAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcutAdvisor, Spring.Aop">
<property name="advice" ref="txAdvice"/>
<property name="patterns">
<list>
<value>LMJ.Service.AdminService.UpdateAdmin</value>
</list>
</property>
</object>
<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop"/>
<tx:advice id="txAdvice" transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="*" rollback-for="errorException" isolation="ReadCommitted" timeout="60"/>
</tx:attributes>
</tx:advice>


方法三:

<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>txAdvice</value>
</list>
</property>
</object>
<tx:advice id="txAdvice" transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="*" rollback-for="errorException" isolation="ReadCommitted" timeout="60"/>
</tx:attributes>
</tx:advice>


如果需要筛选方法,这样配置:

<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
</list>
</property>
</object>
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice" ref="txAdvice"/>
<property name="MappedNames">
<list>
<value>UpdateAdmin</value>
</list>
</property>
</object>
<tx:advice id="txAdvice" transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="*" rollback-for="errorException" isolation="ReadCommitted" timeout="60"/>
</tx:attributes>
</tx:advice>


方法四:

<object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator,Spring.Aop">
<property name="ObjectNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>transactionInterceptorName</value>
</list>
</property>
</object>
<!--拦截器,定义事务策略-->
<object id="transactionInterceptorName" type="Spring.Transaction.Interceptor.TransactionInterceptor,Spring.Data">
<property name="TransactionAttributes">
<name-values>
<add key="UpdateAdmin" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
<property name="TransactionManager">
<ref local="HibernateTransactionManager" />
</property>
</object>


方法五:

<object type="Spring.Aop.Framework.AutoProxy.TypeNameAutoProxyCreator,Spring.Aop">
<property name="TypeNames">
<list>
<value>LMJ.Service.AdminService</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>transactionInterceptorName</value>
</list>
</property>
</object>
<object id="transactionInterceptorName" type="Spring.Transaction.Interceptor.TransactionInterceptor,Spring.Data">
<property name="TransactionAttributes">
<name-values>
<add key="UpdateAdmin" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
<property name="TransactionManager">
<ref local="HibernateTransactionManager" />
</property>
</object>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐