我在Spring批处理中具有编写器简单批处理作业和读取器-处理器配置。在处理器中,我调用存储过程进行一些数据库更新, 正常流程工作正常,但是只要执行存储过程后发生任何异常,更新记录就不会回滚。
@配置 公共课程StudentJobConfig {
@Bean
ItemReader<Student> studentReader() {
// reads data from database
}
@Bean
ItemProcessor<Student, Student> studentProcessor() {
// execute the stored procedure
}
@Bean
Step studentStep(ItemReader<Student> studentReader,
ItemProcessor<Student, Student> studentProcessor,
StepBuilderFactory stepBuilderFactory) {
return stepBuilderFactory.get("StudentStep")
.<Student, Student>chunk(1)
.reader(studentReader)
.processor(studentProcessor)
.build();
}
@Bean
Job inMemoryStudentJob(JobBuilderFactory jobBuilderFactory,
@Qualifier("studentStep") Step studentStep) {
return jobBuilderFactory.get("StudentJob")
.incrementer(new RunIdIncrementer())
.flow(studentStep)
.end()
.build();
}
}