Transactional annotation to rollback for every checked exception - with AspectJ

吃可爱长大的小学妹 提交于 2020-08-09 18:28:53

问题


I would like to use @Transactional annotation (org.springframework.transaction.annotation) for transactions management. I need the rollback to occur for every exception (not just unchecked exceptions), so I use:

@Transactional (rollbackFor = Exception.class)

I use AspectJ mode, and it's working fine.

The problem is, I don't want the developer to have to add the rollbackFor attribute every time. I found this answer, that suggests to extend the @Transactional annotation, like so:

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(rollbackFor=Exception.class)
public @interface TransactionalWithRollback {
}

and use the new annotation instead of the original one. However, this approach is not working for me. I don't see that the AjcClosure files are created when I build the project, for those methods that were annotated with the extended annotation. They are created as expected for methods annotated by the original Transactional annotation.

Does this solution doesn't work with AspectJ? Possibly AspectJ handles only the original Transactional annotation? Is there another solution for my problem, that can work with AspectJ so that we don't have to specify the rollbackFor attribute every time?

Thanks.

来源:https://stackoverflow.com/questions/62875839/transactional-annotation-to-rollback-for-every-checked-exception-with-aspectj

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