我正在使用 Spring Batch,我的步骤配置如下:
@Bean
public Step testStep(
JdbcCursorItemReader<TestStep> testStageDataReader,
TestStepProcessor testStepProcessor,
CompositeItemWriter<Writer> testWriter,
PlatformTransactionManager transactionManager,
JobRepository jobRepository) {
return stepBuilderFactory
.get("TESTING")
.<>chunk(100)
.reader(testStageDataReader)
.processor(testStepProcessor)
.writer(testWriter)
.transactionManager(transactionManager)
.repository(jobRepository)
.build();
}
在我的作家中:
void write(List<? extends TestEntity> items) {
try {
testRepository.saveAll(items);
} catch (Exception exp) {
log.error("Exception while writing the batch", Exp);
//If there is an exception try individual items and skip filed ones
items.forEach(eachTask -> {
try {
testRepository.save(eachTask);
} catch (Exception exp) {
logException(exp, eachTask.getId());
}
});
}
使用代码,我希望如果批次出现问题,那么我将尝试单个项目并跳过失败的项目。
然而,这并没有发生。似乎事务丢失并且未恢复。