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

22 篇文章 0 订阅
17 篇文章 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>

方法二:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值