昨天发现在用一个 service 中 调用 多个 dao 的时候,事务不能正常处理,数据库不能回滚
查阅了一些资料,开始以为是对异常捕捉的问题参见:http://dev.youkuaiyun.com/article/82/82479.shtm
于是在action中也对service 的异常进行捕捉,但是无效.
又再次GOOGLE,在 http://www.javaeye.com/topic/17368?page=4 找到了答案
抛的异常必须是一个Unchecked Exception,Spring才会去处理.如果要允许任何checked的应用异常在callback代码中抛出,就必须要在transactionAttributes的props中配置这个checked Exception.
配置如下:
BeanNotFoundException为自己定义的exception


关于checked exception 和 unchecked exception