Spring @Transactional RollbackFor不起作用

编程入门 行业动态 更新时间:2024-10-12 03:19:32
本文介绍了Spring @Transactional RollbackFor不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有类似下面的代码

public abstract class AffltTransactionService implements IAffltTransactionService { .... @Override @Transactional public void processTransactions(List<? extends AffltTransaction> transactions) { for (AffltTransaction transaction : transactions) { if (transaction != null) { processTransaction(transaction); } } } private void processTransaction(AffltTransaction transaction) { try { processTransactionInternal(transaction); } catch (Exception exception) { affltTransactionError = new AffltTransactionError(null, null, "error", new Date()); saveAffltTransactionError(affltTransactionError); log.error(exception.getLocalizedMessage()); } } @Transactional(readOnly=false, rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void processTransactionInternal(AffltTransaction transaction) {

processTransactionInternal引发ServiceUnAvailableException,该异常扩展了RuntimeException

processTransactionInternal throws ServiceUnAvailableException which extends RuntimeException

但是,尽管具有rollbackFor = Exception.class,但事务并未回滚. 你能帮忙吗?

But the transaction is not getting rolled back despite having rollbackFor = Exception.class . Can you please help.

推荐答案

@Transactional注释将无效,因为Spring在带注释的类之上创建代理,并且实现了方面定义的功能通过代理.因此,当您从类中调用该方法时,它不会通过代理进行访问,因此不会创建和/或回滚事务.

@Transactional annotation won't have any effect if you are calling the method directly, since Spring creates proxies above annotated classes and the aspect-defined functionality is implemented by proxy. So, when you call the method from within your class it doesn't get through proxy, and hence no transcation is created and/or rolled back.

看看春季参考以获取详细说明.

更多推荐

Spring @Transactional RollbackFor不起作用

本文发布于:2023-10-26 07:07:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   Spring   Transactional   RollbackFor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!