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

来源:互联网 发布:在线课程制作软件 编辑:程序博客网 时间:2024/04/28 07:27

方法一:

<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>


原创粉丝点击