I need to avoid process same file twice in Spring Batch project. Therefore I need to put file name as a Job Parameter. However, I know file name only in step1, not before the job execution. Therefore I can't pass file name as a job parameter while launching a job. My question is that, is there any other way to pass job parameter in step1 after get to know file name?
Asked
Active
Viewed 282 times
0
-
If you don't know the file name upfront, then you can't use it as a job parameter to benefit from the design of Spring Batch that prevents a successful job instance to run twice as described here: https://stackoverflow.com/a/61385731/5019386. So the answer by Julien is correct. In your case, you can store the name of each processed file in a persistent store and check if the current file has been already processed or not before proceeding. If the file name is not enough, a common technique is to checksum the file (md5, sha1, etc) and see if the content is the same as well. – Mahmoud Ben Hassine Apr 26 '20 at 12:53
1 Answers
1
You don't need to add a parameter to Spring Batch, you need to pass data between steps. Here are some ways to do that => Storing in JobExecutionContext from tasklet and accessing in another tasklet
Hope it helps !

Julien
- 48
- 4
-
Man, Thank you for your answer but how I can avoid processing same file twice with passing data between steps? – Musa Mammadov Apr 24 '20 at 20:05
-