spring的异常是运行时异常,不用捕捉,而且spring声明式事务(默认)是不回滚check异常的。The final facet of the transaction pentagon is a set of rules that define what exceptions prompt a rollback and which ones do not. By default, transactions are rolled back only on runtime exceptions and not on checked exceptions. (This behavior is consistent with rollback behavior in EJBs.)所有在做事务处理时要注意下顺便
超出了jvm的控制范围.用try catch捕获,反馈异常,也只能做这点了,呵呵
prompt a rollback and which ones do not. By default, transactions are rolled
back only on runtime exceptions and not on checked exceptions. (This behavior
is consistent with rollback behavior in EJBs.)所有在做事务处理时要注意下顺便
不回滚,那就破坏了ACID原则
<tx:method name="get*" read-only="false" rollback-for="IOException"/>
意思是:RuntimeException及其子异常回滚,IOException回滚,其他异常不回滚可以根据自己的业务需要配置哪些异常需要回滚
Spring的DataAccessException是运行时异常,无需try catch 或 throw,他会自动抛出
如果想拦截,只需要在action中catch或者配置异常类,然后统一转向到一个错误页面即可。
spring声明式事务有5个属性:
Rollback rules 这个属性就是指定异常的回滚条件(上面只是说的是缺省的情况下)<tx:attributes>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
</tx:attributes>
这样无论什么异常都会回滚