Skip to content
Advertisement

How to pass data into spring batch ItemProcessor?

I have a CSV file that contains records of data (cases), for which I created a caseDTO object , however some of the properties of the caseDTO must be field from data included in the file name (every file must has a name with strict structure that contains some data).

What i want to achieve is to pass the data included in the file name to the item processor where i will append this data into every caseDTO before passing it to the item writer.

Does any one knows how to pass data to a step itemProcessor when I launch the job from the controller?

Thanks in advance.

Advertisement

Answer

the simplest solution is to set the dynamic parameters in the job parameters so the step’s writer , processor , reader can have access to it . by injecting their values as following

@Value("#{jobParameters['fileName']}") public void setFileName(final String name) { //... }

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement