I read SO related questions but the solutions don't work for me.
I get the org.springframework.batch.item.ReaderNotOpenException: Reader must be open before it can be read
exception.
Below is my configuration:
@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(""+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();
}
The inputZipFile variable is set properly and the file exists on the drive.
I checked in the FlatFileItemReader code and the ReaderNotOpenException occurs when the reader member of the reader class is not set. The reader member is set in doOpen method.
It looks that doOpen is not called. The question is why ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…