after-throwing 捕获 分布式事务异常的 疑问

本文探讨了在Spring框架下使用分布式事务处理时遇到的问题,特别是如何利用AOP进行异常捕捉并记录日志,作者详细描述了配置及具体实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目采用 三层结构 用到了分布式事务,包裹的是services层的方法,相关配置如下:

<bean id="abstractTransactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>

<property name="transactionAttributes">
<props>
<prop key="find*"> PROPAGATION_REQUIRED,readOnly,-OrderException </prop>
<prop key="get*"> PROPAGATION_REQUIRED,readOnly,-OrderException </prop>
<prop key="save*"> PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException </prop>
<prop key="add*"> PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException </prop>
<prop key="del*"> PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException </prop>
<prop key="remove*"> PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException </prop>
</props>
</property>
</bean>


<bean id="ocsServices"
class="services.OcsServices">
<property name="smp">
<ref bean="hqlExecutor1"/>
</property>
<property name="daoScpList">
<list>
<ref bean="hqlExecutor1"/>
<ref bean="hqlExecutor2"/>
</list>
</property>
</bean>

<bean id="ocsconfigService" parent="abstractTransactionProxy">
<property name="target">
<ref bean="ocsServices"/>
</property>
</bean>

<aop:config>
<aop:aspect id="prefixAspect4" ref="logInterceptor">
<aop:pointcut id="prefixPointCut4"
expression="execution(* services.OcsServices.add(Object)) and args(Object)" />
<aop:after-throwing
pointcut-ref="prefixPointCut4" method="afterThrowing"
throwing="dataAccessException"/>
</aop:aspect>
</aop:config>

<bean id="logInterceptor" class="aop.LogAop">
</bean>

<bean id="prefixController" class="mvc.PrefixController">
........
<!--
将ocsconfig-service中配置的ocsServices注入。
-->
<property name="ocsServices">
<ref bean="ocsconfigService"/>
</property>
<!--
设置controller可以转发的页面。
-->
.....
</bean>

目前的想法就是希望 <aop:aspect id="prefixAspect4" ref="logInterceptor"> 能捕获提交事务时如果出现异常能捕获这个异常,并记录日志说明执行这个操作没有成功,但是自己的测试却是afterThrowing方法不会执行,而其他的after,afterreturn等都可以正常工作。
下面是class OcsServices的add方法

public void add(Object o)
{
Prefix oo = (Prefix)o;

Iterator it = this.getDaoScpList().iterator();
while(it.hasNext())
{
IPrefixDao ipd = (IPrefixDao)it.next();
ipd.savePrefix(oo);
}
}


希望各位大大能指导指导,是否是设计就有问题还是哪个配置不正确。谢谢
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值