How to access jobparameter from ItemReader class of Spring batch job in spring boot web application
<p>I am launching a spring batch Job from my controller. I need to access the job parameter <code>fileName</code> from configured custom <code>ItemReader</code> via java based configuration.But I always gets the fileName as null from my ItemReader. Please help.
I am launching like this because I have to change ItemReader file according to the user request.</p>

<p>My Controller : </p>

<pre><code>@RestController
@RequestMapping(value = "/")
public class SimpleController {


@Autowired
Step step;

@Autowired
private JobBuilderFactory jobs;

@Autowired
private StepBuilderFactory steps;

@Autowired
private JobRepository jobRepository;

@Autowired
JobLauncher jobLauncher;

@RequestMapping(method = RequestMethod.GET)
public void StartJob() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
    JobParameter param = new JobParameter("ValueBeingSetFromRequestHeader");
    HashMap map = new HashMap&lt;String, JobParameter&gt;();
    map.put("fileName",param);
    SimpleJob job = new SimpleJob("test");
    job.addStep(step);
    System.out.println(jobRepository);
    job.setJobRepository(jobRepository);

    System.out.println( jobRepository.getLastJobExecution(job.getName(), new JobParameters(map)));

    jobLauncher.run(job, new JobParameters(map));

}
</code></pre>

<p>}</p>

<p>And my Job step configuration class is   </p>

<pre><code>public class ProducerBatchJobConfigurer {


private String fileName;

public String getFileName() {
    return fileName;
}
@Value("#{jobParameters['fileName']}")
public void setFileName(String fileName) {
    this.fileName = fileName;
}

@Bean
public ItemReader reader() {
    System.out.println(fileName);
    if (fileName == null)
        return new DummyReader();
    FlatFileItemReader faltFileReader =  new FlatFileItemReader();

    faltFileReader.setResource(new FileSystemResource(new File(fileName)));
    faltFileReader.setResource(new FileSystemResource(new File(fileName)));
    DefaultLineMapper&lt;KafkaMessage&gt; lineMapper = new DefaultLineMapper&lt;KafkaMessage&gt;();
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer());
    lineMapper.setFieldSetMapper(new CSVFieldMapper());
    faltFileReader.setLineMapper(lineMapper);
    return faltFileReader;
}

@Bean
public ItemProcessor processor() {
   return new CustomItemProcessor();

}

@Bean
public ItemWriter writer() {
    return new KafkaWriter();
}



@Bean
public Step step1(StepBuilderFactory stepBuilderFactory,
                  ItemReader reader, ItemWriter writer,
                  ItemProcessor processor) {
    System.out.println("ddddddddddddddd");
    return stepBuilderFactory.get("step1")
            .chunk(10).reader(reader)
            .processor(processor).writer(writer).build();
}
@Bean
public StepScope stepScope() {
    final StepScope stepScope = new StepScope();
    stepScope.setAutoProxy(true);
    return stepScope;
}
@Bean
public JobScope jobScope(){
    return new JobScope();
}
}
</code></pre>