日期:2014-05-20  浏览次数:20769 次

知道spring中的aop事务和日志的处理请进
我使用了spring2.5的aop处理事务,是使用注解的方式处理的,代码如下:

---------------------------
@Transactional(rollbackFor = Exception.class)
public void receiveVpAreasDatas(List<Area> areaList,List<ViewPoint> vpList,List<Mp3> mp3List){

  if(areaList != null){

this.receiveAreaDatas(areaList);
  }

  if(vpList != null){

this.receiveVpDatas(vpList);
  }

 if(mp3List != null){

this.receiveMp3Datas(mp3List);
 }


}

---------------------------

我对上面的代码进行了测试,如果receiveAreaDatas、receiveVpDatas
receiveMp3Datas中,无论哪个方法抛出了异常的话,事务都是可以回滚的。
是没有任何问题的。

但是如果服务器上代码有抛出异常的话,我想
把这些异常信息写入日志,方便以后查询,代码如下:

-----------------------------
@Transactional(rollbackFor = Exception.class)
public void receiveVpAreasDatas(List<Area> areaList,List<ViewPoint> vpList,List<Mp3> mp3List){

  try{  

  if(areaList != null){

this.receiveAreaDatas(areaList);
  }

  if(vpList != null){

this.receiveVpDatas(vpList);
  }

 if(mp3List != null){

this.receiveMp3Datas(mp3List);
 }
}catch(Exception e){

  logger.debug("出错!");
}

}

-----------------------------

加入了异常处理后,我发现事务无法回滚了。
不知道是怎么回事。
请高手指教一下。








------解决方案--------------------
你把异常抓走了 spring容器接不到了啊
------解决方案--------------------
当然不会有了呀,

你的annotation告诉spring的conatiner rollbackFor = Exception.class
有exception时候 事务回滚,

但是你的方法现在没有exception抛出呀,已经被你自己处理了。

catch(Exception e){ 

logger.debug("出错!"); 

throw e;


再throw出来哟。
------解决方案--------------------
探讨
当然不会有了呀,

你的annotation告诉spring的conatiner rollbackFor = Exception.class
有exception时候 事务回滚,

但是你的方法现在没有exception抛出呀,已经被你自己处理了。

catch(Exception e){

  logger.debug("出错!");

throw e;
}

再throw出来哟。