street
street

Reputation: 51

How to write a custom Flat File Item Reader

I am new to Spring batch. I wanted to ask how can I write a custom flat file item reader in Spring batch. I know there is one generic FlatFileItemReader available in Spring batch, but we want to add some business logic while reading then how to write a custom flat file reader.

Thanks in advance

Upvotes: 1

Views: 10028

Answers (2)

Ashok Singh
Ashok Singh

Reputation: 243

I have done same thing for MultiResourceItemReader, you can extend FlatFileReader and copy complete code of FlatFileReader. Then you can add your own method.

Upvotes: 1

Saifuddin Merchant
Saifuddin Merchant

Reputation: 1171

If the in-build logging provided in the FlatFileItemReader is not sufficient for your needs,

  1. Grab the code for the FlatFileItemReader - https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java
  2. Rename the class to you class-name/package name
  3. Add loggers as needed and use

I don't recommend this - in more cases you would be better off debugging your code with a debugger.

Upvotes: 0

Related Questions