2

I want to pass an array of String values, like this: String[] countries = {"IN","BR","CO"}; My job launcher looks like this:

public class App {
public static void main(String[] args) {
    String[] springConfig  = 
        {   "spring/batch/config/database.xml", 
            "spring/batch/config/context.xml",
            "spring/batch/jobs/job-report.xml" 
        };
    ApplicationContext context = 
            new ClassPathXmlApplicationContext(springConfig);
    JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job job = (Job) context.getBean("blueReportJob");
    try {
        JobExecution execution = jobLauncher.run(job, new JobParameters());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("*** END");
}

}

JamesD
  • 679
  • 10
  • 36
  • I want my Process step to have a list of countries that that I should filter out. I was trying to setup the JobParameters with that list, but maybe there is a better way to do this? – JamesD Sep 22 '17 at 02:36

1 Answers1

0

First of all , you shouldn't be using JobParameters since those are meant for some other use case.

I didn't found it clearly written on Spring Websites so quoting from here

JobParameters: a set of parameters used to start a batch job. It categorizes each JobInstance.

i.e. JobParameters class is meant to distinguish among various job instances and that is very much a Spring Batch meta data concern.

The data that you are talking about ( list of countries ) seems application logic data ( since you mentioned to use in application processor ) , I would suggest to make it available via other ways - as part of application bootstrapping.

Traditionally, we use application properties, hard coded constants ( lists , maps etc ) , values from files, databases , command line parameters etc etc to provide data to application logic. You should use one of those ways instead of JobParameters .

This SO Question might help if choosing parameter way anyhow.

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98