日期:2014-05-17  浏览次数:20805 次

spring事务控制
3个service实现类:classA,classB,classC,调用顺序如下,spring事务控制在每个方法上加了事务,现在classC的cc方法发送了异常,导致classB的bb()方法回滚了,
请教高手出现这现象的原因是什么?如果想实现classB的bb方法不因bb1异常而回滚,需要怎么处理?
classA{
    … … … … … …… …
    public void aa()
    {
     classB.bb();
    }
    
}

classB{

public void bb()
{
…… …… …… ……;
try
{
bb1();
}
  catch
  {
  
  }
}

private void bb1()
{
classC.cc();
}
}

classC
{
   public void cc()
   {
     …………………………;
     …………………………;
   }
}

控制台打印信息:
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:695)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy24.entrance(Unknown Source)

事务控制配置如下:
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" />
</tx:advice>

<aop:config>
<aop:pointcut id="allMethod" expression="execution(* *..service.impl.*.*(..)) " />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod" />
</aop:config>
spring事务控制

------解决方案--------------------