SpringBatch—如何将从csv读取的行存储到执行上下文中以实现可重启性

avkwfej4  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(370)

我不确定flatfileitemreader是否有能力在遇到异常时存储最后一行。因此,当我重新运行批处理应用程序时,它将能够从最后一行继续。
任何实现以下使用原因的示例都会有帮助,谢谢!

public static FlatFileItemReader<Employee> reader(String path){
    FlatFileItemReader<Employee> reader = new FlatFileItemReader<Employee>();

    reader.setResource(new ClassPathResource(path));
    reader.setLineMapper(new DefaultLineMapper<Employee>() {
    {
     setLineTokenizer(new DelimitedLineTokenizer() {
     {
       setNames(new String[] {"firstName", "lastName", "emailId"});
     }
   });
   setFieldSetMapper(new BeanWrapperFieldSetMapper<Employee>() {
     {
       setTargetType(Employee.class);
     }
   });
 }
});

return reader;
}}
hec6srdp

hec6srdp1#

我认为这是 FlatFileItemReader ```
DefaultLineMapper
Now that the basic interfaces for reading in flat files have been defined, it becomes clear that three basic steps are required:

Read one line from the file.

这意味着如果在作业中将chunk size设置为1,并且reader在第195行失败,那么下次作业将选择chunk no 195并从第195行继续。另外,在应用程序启动时,spring会检查失败的执行,并自动重新启动它。一些文档:
重试
可重启性

相关问题