Override SpringBatch jobLauncher with command line arguments

时间:2019-04-17 02:15:32

标签: java spring spring-batch

I have override jobLauncher() in BatchConfig in my SpringBatchapplication as follow:

 @Bean
public JobLauncher jobLauncher() throws SQLException {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher() {
        JobParameters params = new JobParametersBuilder()
                .addString("param1", "ABC")
                .addLong("time",System.currentTimeMillis())
                .toJobParameters();

        @Override
        public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
            return super.run(job, params);
        }
    };

    jobLauncher.setJobRepository(getJobRepository());

    return jobLauncher;
}

However, now I want param1 to be passed in as a command line argument. Is this possible while overriding jobLauncher() at the same time?

0 个答案:

没有答案