我有类似下面的代码
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不起作用
发布评论