方法1 <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>
方法2 <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>
方法3 <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>
如果需要筛选方法,这样配置:
方法3-2 <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>
方法4 <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>
方法5 <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>