项目采用 三层结构 用到了分布式事务,包裹的是services层的方法,相关配置如下:
目前的想法就是希望 <aop:aspect id="prefixAspect4" ref="logInterceptor"> 能捕获提交事务时如果出现异常能捕获这个异常,并记录日志说明执行这个操作没有成功,但是自己的测试却是afterThrowing方法不会执行,而其他的after,afterreturn等都可以正常工作。
下面是class OcsServices的add方法
希望各位大大能指导指导,是否是设计就有问题还是哪个配置不正确。谢谢
<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);
}
}
希望各位大大能指导指导,是否是设计就有问题还是哪个配置不正确。谢谢