Spring Batch: org.springframework.batch.item.ReaderNotOpenException: Reader 必須先開啟才能閱讀
2022-09-01 13:41:26
我阅读了与SO相关的问题,但解决方案不适合我。
我得到例外。org.springframework.batch.item.ReaderNotOpenException: Reader must be open before it can be read
以下是我的配置:
@Bean
@StepScope
public ItemReader<Player> reader(@Value("#{jobParameters[inputZipfile]}") String inputZipfile) {
final String [] header = { .. this part omitted for brevity ... };
FlatFileItemReader<Player> reader = new FlatFileItemReader<Player>();
System.out.println("\t\t\t\t\t"+inputZipfile);
reader.setResource(new ClassPathResource(inputZipfile));
reader.setLineMapper(new DefaultLineMapper<Player>() {{
setLineTokenizer(new DelimitedLineTokenizer() {{
setNames( header );
}});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Player>() {{
setTargetType(Player.class);
}});
}});
reader.setComments( header );
return reader;
}
@Bean
@StepScope
public ItemProcessor<Player, PlayersStats> processor(@Value("#{jobParameters[statType]}") String statType,
@Value("#{jobParameters[season]}") String season){
PlayersStatsProcessor psp = new PlayersStatsProcessor();
psp.setStatisticType( StatisticType.valueOf(statType) );
psp.setSeason( season );
return psp;
}
@Bean
@StepScope
public ItemWriter<PlayersStats> writer(){
return new CustomWriter();
}
@Bean
public Job generateStatisticsJob() {
return this.jobs.get("generateStatisticsJob")
.incrementer(new RunIdIncrementer())
.start(processPlayerStats())
//.end()
.build();
}
@Bean
public Step processPlayerStats() {
return this.steps.get("processPlayerStats")
.<Player, PlayersStats> chunk(10)
.reader(reader(null))
.processor(processor(null,null))
.writer(writer())
.build();
}
输入ZipFile变量设置正确,并且该文件存在于驱动器上。我签入了 FlatFileItemReader 代码,当未设置 reader 类的 reader 成员时,会发生 ReaderNotOpenException。读取器成员在 doOpen 方法中设置。看起来 doOpen 没有调用。问题是为什么?