Я получаю NullPointerException в reader.read (). Я не знаю, что я делаю неправильно. Ниже мой класс Reader.
org.springframework.batch.item.file.FlatFileParseException: Ошибка синтаксического анализа в строке: 1 в ресурсе = [файл [C: \ RDS \ finalObj.txt] ], вход = [СТУДЕНТ, 1, Калдане]
public class MultiLineTradeItemReader extends AbstractItemCountingItemStreamDelegateReader<Student> {
@Override
protected Student doRead() throws Exception {
Student t=null;
t= studentFieldSetMapper().mapFieldSet(reader.read());
return t;
}
@Override
protected void doOpen(ExecutionContext executionContext) throws Exception {
reader= new FlatFileItemReader<FieldSet>();
try {
reader.setResource(new FileSystemResource("C:\\RDS\\finalObj.txt"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setName("myReader");
reader.setLineMapper(orderFileLineMapper());
reader.open(executionContext);
}
@Bean
public PatternMatchingCompositeLineMapper orderFileLineMapper() {
PatternMatchingCompositeLineMapper lineMapper =
new PatternMatchingCompositeLineMapper();
Map<String, LineTokenizer> tokenizers = new HashMap<>(3);
tokenizers.put("STUDENT*", studentDelimeter());
lineMapper.setTokenizers(tokenizers);
Map<String, FieldSetMapper> mappers = new HashMap<>(2);
mappers.put("STUDENT*", studentFieldSetMapper());
lineMapper.setFieldSetMappers(mappers);
return lineMapper;
}
@Bean
public FieldSetMapper<Student> studentFieldSetMapper() {
BeanWrapperFieldSetMapper<Student> fieldSetMapper = new BeanWrapperFieldSetMapper();
fieldSetMapper.setPrototypeBeanName("student");
return fieldSetMapper;
}
@Bean
@Scope("prototype")
public Student student() {
return new Student();
}
private LineTokenizer studentDelimeter() {
DelimitedLineTokenizer delimitedLineTokenizer= new DelimitedLineTokenizer(",");
delimitedLineTokenizer.setNames("tableName","rollno","studentname");
return delimitedLineTokenizer;
}
}