Spring 批处理 - 如何将从 CSV 读取的行存储到可重新启动的执行上下文中
Spring Batch - How to store lines read from CSV into a execution context for Restartability
我不确定 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;
}}
我认为这是 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.
这意味着如果您在作业中将块大小设置为 1,并且 reader 在第 195 行失败,则下次作业将选择第 195 号块并从第 195 行继续。
同样在应用程序启动时 spring 检查失败的执行并自动重新启动它。
一些文档:
我不确定 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;
}}
我认为这是 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.
这意味着如果您在作业中将块大小设置为 1,并且 reader 在第 195 行失败,则下次作业将选择第 195 号块并从第 195 行继续。 同样在应用程序启动时 spring 检查失败的执行并自动重新启动它。 一些文档: