noRollbackFor not always working on unchecked exceptions (not a duplicate)

浪尽此生 提交于 2019-12-06 06:01:07

The behavior you see has nothing to do with transaction handling but with exception translation. By default when a class is annotated with @Repository Spring will register a PersistenceExceptionTranslationInterceptor which will translate exceptions to one of the Spring DataAccessExceptions. By default it translates all exceptions UNLESS the exception thrown is declared in the throws clause.

This exception translation happens before the TransactionInterceptor and that way there is never an IllegalArgumentException thrown because that already got translated into something else.

Create your won custom exception (Extending from exception ) and apply noRollBackFor you custom exception class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!