知道spring中的aop事务和日志的处理请进

Sam_Deep_Thinking
Java领域新星创作者
博客专家认证
2009-08-31 01:36:56
我使用了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("出错!");
}

}

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

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






...全文
160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcj_up 2009-08-31
  • 打赏
  • 举报
回复
学习啦
@Transactional(rollbackFor = Exception.class)
必需跑出初五才能处理。。。。
Sam_Deep_Thinking 2009-08-31
  • 打赏
  • 举报
回复
哦,我一下子陷入到细节当中了。
没有去想throw e;
thank 各位。
eyuanliang 2009-08-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 inthirties 的回复:]
当然不会有了呀,

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

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

catch(Exception e){

  logger.debug("出错!");

throw e;
}

再throw出来哟。
[/Quote]
细心点想问题就能想到的! 这就是我们新手的通病了!  
inthirties 2009-08-31
  • 打赏
  • 举报
回复
当然不会有了呀,

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

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

catch(Exception e){

logger.debug("出错!");

throw e;
}

再throw出来哟。
Sam_Deep_Thinking 2009-08-31
  • 打赏
  • 举报
回复
我知道,所以要如何处理?
请说说。
lijing0511 2009-08-31
  • 打赏
  • 举报
回复
你把异常抓走了 spring容器接不到了啊

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧