title: Accessing Job Parameters Spring Batch
body: <p>I have been struggling with accessing Job Parameters of a job using spring batch. Here is my implementation so far.</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  @PropertySource("classpath:batch.properties")
  public class CSVBatchServiceImpl extends StepExecutionListenerSupport implements CSVBatchService {
      private static final Logger LOGGER = LoggerFactory.getLogger(CSVBatchServiceImpl.class);
      @Autowired
      public JobBuilderFactory jobBuilderFactory;
      @Autowired
      public StepBuilderFactory stepBuilderFactory;
  
      private QuestionReader questionReader = new QuestionReader();
  
      @Bean(name = "importQuestionsJob")
      public Job importQuestionsJob() {
          return jobBuilderFactory.get("importQuestionsJob")
                  .incrementer(new RunIdIncrementer())
                  .flow(step1())
                  .end()
                  .build();
      }
  
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .&lt;Question, Question&gt;chunk(2)
                  .reader(questionReader.reader())
                  .processor(processor())
                  .build();
      }
  
      @Bean
      public QuestionProcessor processor() {
          return new QuestionProcessor();
      }
  }
  
  class QuestionReader extends StepExecutionListenerSupport {
      private static final Logger LOGGER = LoggerFactory.getLogger(QuestionReader.class);
  
      //TODO: remove this
      private static JsonNode getJsonNode(String str) {
          try {
              ObjectMapper mapper = new ObjectMapper();
              return mapper.readTree(str);
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
      }
  
      @Bean
      public FlatFileItemReader&lt;Question&gt; reader() {
          FlatFileItemReader&lt;Question&gt; reader = new FlatFileItemReader&lt;&gt;();
          //TODO get this as a parameter
          reader.setResource(new ClassPathResource("duplicateLabels.csv"));
          reader.setLinesToSkip(1);
          reader.setLineMapper(new DefaultLineMapper&lt;Question&gt;() {{
              setLineTokenizer((new DelimitedLineTokenizer() {{
                  setNames(new String[]{"label", "body", "real_answer"});
              }}));
              setFieldSetMapper(new QuestionFieldSetMapper());
          }});
          return reader;
      }
  
      private static class QuestionFieldSetMapper implements FieldSetMapper&lt;Question&gt; {
          public Question mapFieldSet(FieldSet fieldSet) {
              Question question = new Question();
              question.setLabel(fieldSet.readString(0));
              question.setBody(getJsonNode(fieldSet.readString(1)));
              question.setRealAnswer(getJsonNode(fieldSet.readString(2)));
              return question;
          }
      }
  }
  </code></pre>
  
  <p>I am calling the job like:</p>
  
  <pre><code>JobParameters parameters = new JobParametersBuilder()
          .addLong("time", System.currentTimeMillis())
          .addString("filePath", "file.csv")
          .toJobParameters();
  jobLauncher.run(importQuestionsJob, parameters);
  </code></pre>
  
  <p>How can I go about accessing the filePath parameter inside reader function?</p>