Tom Clifford
Tom Clifford

Reputation: 1

Spring Batch command line parameters - series of codes?

Good day. I could not find an answer for this from google or from the search in stackoverflow, so please be patient if I missed a post for it.

I need to run a Spring Batch (v3.x) using CommandLineJobRunner because we need to submit run parameters, including a flag to process all codes, or process a subset of codes.

I'm thinking we might use a parameter listing the codes (if the process_all flag is set to 'N'). The params might look like this:

-Dexec.args="birthdayBatchConfig.xml birthdayBatchJob process_all=Y run_date=022017" I plan to take the run day from the day of the run)

I would then add the subset of codes to process like: code_list=[22 34 56 73 82 84 86 87} ...I would then get the code_list param and parse out the codes with a Tokenizer. I'm doing some experimenting to see if this might work, but if someone has had to do this before, any advice would be helpful. Thank you.

Upvotes: 0

Views: 616

Answers (1)

Nghia Do
Nghia Do

Reputation: 2658

I'm thinking a simple way as this

  1. Passing code list a single parameter as codes=22,34,56,73
  2. In Reader or anyplace you need to use it, map it as

@Value("#{jobParameters['codes']}") private String[] codes;

Spring will handle the split with commas separator for us behind the scene.

Let me know if you have more question

Upvotes: 1

Related Questions