【发布时间】:2022-01-13 09:13:45
【问题描述】:
我正在为我的应用程序使用 SpringBatch。在其中一个批处理作业中,我需要处理多个数据。每个数据都需要多次数据库更新。我需要为一项数据进行一项交易。意思是,如果在处理一个数据时抛出异常,则该数据的数据库更新会回滚,然后继续处理下一个数据。
我已将所有数据库更新放在服务层的一种方法中。在我的 springbatch tasklet 中,我为每个数据调用该方法,如下所示;
for (RequestViewForBatch request : requestList) {
orderService.processEachRequest(request);
}
在服务类中方法是这样的;
Transactional(propagation = Propagation.NESTED, timeout = 100, rollbackFor = Exception.class)
public void processEachRequest(RequestViewForBatch request) {
//update database
}
执行任务时,它给了我这个错误信息
org.springframework.transaction.NestedTransactionNotSupportedException: Transaction manager does not allow nested transactions by default - specify 'nestedTransactionAllowed' property with value 'true'
但我不知道如何解决这个错误。
任何建议将不胜感激。提前致谢。
【问题讨论】:
标签: spring-boot transactions spring-batch