title: How start the batch from rest service. The afterJob runs but EnableBatchProcessing runs only after deployed
body: <p>I followed the tutorial <a href="https://spring.io/guides/gs/batch-processing/" rel="nofollow noreferrer">https://spring.io/guides/gs/batch-processing/</a> which basically reads a spreadsheet and insert the data in database once the application is started. I want to execute the reading process every time a rest service is evoked, so I added a controller in this application. To call the job I followed the suggestion in <a href="https://stackoverflow.com/questions/20248910/how-to-trigger-a-job-using-a-rest-web-service">How to trigger a job using a rest web service?</a> and now it rises my issue: whenever I called the rest service it runs only the afterJob method. I read <a href="https://stackoverflow.com/questions/25122103/how-to-select-which-spring-batch-job-to-run-based-on-application-argument-spri">how to select which spring batch job to run based on application argument - spring boot java config</a> (which has certain similiarity with my issue) and the excellent blog post pointed in it but I am still stuck. I want to call "public ItemReader reader()" after the rest service and I expect the same flow to be followed as it is done when the application started via main(). I mean, the same flow as when it is deployed by springboot. I guess my confusion lies in @EnableBatchProcessing or JobExecutionListenerSupport but I am really stuck on it.
  Below are the most important snippet.</p>
  
  <p><strong>Controller</strong>  </p>
  
  <pre><code>@Autowired
  JobLauncher jobLauncher;
  
  @Autowired
  Job job;
  
  @RequestMapping("/runit")
  public void handle() throws Exception{
         JobParameters jobParameters =
                         new JobParametersBuilder()
                         .addLong("time",System.currentTimeMillis()).toJobParameters();
          jobLauncher.run(job, jobParameters);
  }
  </code></pre>
  
  <p><strong>Listener</strong></p>
  
  <pre><code>@Component
  public class JobCompletionNotificationListener extends   
      JobExecutionListenerSupport {
  
      @Override
      public void afterJob(JobExecution jobExecution) {
          if(jobExecution.getStatus() == BatchStatus.COMPLETED) {
  </code></pre>
  
  <p><strong>Batch Configuration</strong></p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class BatchConfiguration {
      // tag::readerwriterprocessor[]
      @Bean
      public ItemReader&lt;Person&gt; reader() {
          FlatFileItemReader&lt;Person&gt; reader = new FlatFileItemReader&lt;Person&gt;();
          reader.setResource(new ClassPathResource("sample-data.csv"));
          reader.setLineMapper(new DefaultLineMapper&lt;Person&gt;() {{
              setLineTokenizer(new DelimitedLineTokenizer() {{
                  setNames(new String[] { "firstName", "lastName" });
              }});
  
              setFieldSetMapper(new BeanWrapperFieldSetMapper&lt;Person&gt;() {{
                  setTargetType(Person.class);
              }});
          }});
  
          return reader;
      }
  
      @Bean
      public ItemProcessor&lt;Person, Person&gt; processor() {
          return new PersonItemProcessor();
      }
  
      @Bean
      public ItemWriter&lt;Person&gt; writer(DataSource dataSource) {
          JdbcBatchItemWriter&lt;Person&gt; writer = new JdbcBatchItemWriter&lt;Person&gt;();
          writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;Person&gt;());
  
          writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)");
  
          writer.setDataSource(dataSource);
          return writer;
      }
  
      @Bean
      public Job importUserJob(JobBuilderFactory jobs, Step s1, JobExecutionListener listener) {
          return jobs.get("importUserJob")
                  .incrementer(new RunIdIncrementer())
                  .listener(listener)
                  .flow(s1)
                  .end()
                  .build();
      }
  
      @Bean
      public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader&lt;Person&gt; reader,
              ItemWriter&lt;Person&gt; writer, ItemProcessor&lt;Person, Person&gt; processor) {
          return stepBuilderFactory.get("step1")
                  .&lt;Person, Person&gt; chunk(10)
                  .reader(reader)
                  .processor(processor)
                  .writer(writer)
                  .build();
      }
  </code></pre>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>application.properties
  # SPRING BATCH (BatchDatabaseInitializer)
  spring.batch.job.enabled=false
  spring.batch.initializer.enabled=false
  </code></pre>