Reputation: 1
I am using Spring batch with spring boot. I am facing problems while processing multiple files.
My Scenario. I have multiple files having different headers, for example:
Sourcefile1.txt:
name, age, salary
ajay, 22, 2000
vijay, 23, 3000
Sourcefile2.txt:
name, address
vijay, india
ajay, uk
I want to process these files using spring boot with spring batch. How can I do this?
Upvotes: 0
Views: 1479
Reputation: 1475
You need to create a spring batch job. Use a reader which will read the file, for reading csv files, there comes an implementation FlatFileItemReader from spring batch. While regsitering this class as a reader bean in spring batch, You can configure this file according to your need while performing the setter injection to it's properties.For example you can set a property linesToSkip of this class, which will exclude the lines which you do not want the spring batch to read, usually we skip the first line of the file as it contains the headers. further you can configure a line mapper to this bean for this there comes another implementation form spring batch itself having name DefaultLineMapper, extend this class if you want to customize your file mapping logic. This is all about the reading part.Now further you can implement the processors and writers provided by spring batch for performing further actions on the data which you have read using the FlatFileReader.
Upvotes: 0