title: Run spring batch job from controller
body: <pre><code>@RestController
  @Controller
  public class DemandeWebbatchControler {
  
  private static final Logger logger = LoggerFactory.getLogger(DemandeWebbatchControler.class);
  
  @Autowired
  @Qualifier("jobLauncher")
  private JobLauncher jobLauncher;
  
  @Autowired
  @Qualifier("demandeJob")
  private Job job;
  
  @Autowired
  JobExplorer jobExplorer;
  
  @Autowired
  DemandeService demandeService;
  
  @Autowired
  private ApplicationContext context;
  
  /*
   * @RequestMapping(value = "/statistiquesCompteurs.xhtml", method =
   * RequestMethod.POST) public String demandeHandle() throws Exception {
   * 
   * try {
   * 
   * JobParameters jobParameters = new JobParametersBuilder().addLong("time",
   * System.currentTimeMillis()) .toJobParameters(); jobLauncher.run(job,
   * jobParameters); } catch (JobExecutionAlreadyRunningException e) {
   * logger.info(e.getLocalizedMessage());
   * 
   * } catch (Exception e) { logger.info(e.getLocalizedMessage()); } List&lt;Demande&gt;
   * d = demandeService.listDemande(); return
   * "Done! Check Console Window for more details: " + " " + d;
   * 
   * }
   */
  
  @RequestMapping(value = "jobs/{jobName}", method = RequestMethod.POST)
  public JobExecutionDto run(@PathVariable String jobName, @Valid @RequestBody JobParam jobParam)
          throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException,
          JobInstanceAlreadyCompleteException {
  
      if (!context.containsBean(jobName)) {
  
          throw new RasterFormatException("Job Not found!");
      }
  
      Job job = context.getBean(jobName, Job.class);
  
      JobParameters jobParameters = getJobParameters(jobParam);
  
      try {
          JobExecution jobExecution = jobLauncher.run(job, jobParameters);
          JobExecutionDto result = new JobExecutionDto();
          BeanUtils.copyProperties(jobExecution, result);
          return result;
      } catch (org.springframework.batch.core.repository.JobRestartException e) {
  
          e.printStackTrace();
      }
  
      return null;
  
  }
  
  @RequestMapping(value = "/jobs/executions/{jobExecutionId}", method = RequestMethod.GET)
  public JobExecutionDto process(@PathVariable Long jobExecutionId) {
  
      JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
      JobExecutionDto result = new JobExecutionDto();
      BeanUtils.copyProperties(jobExecution, result);
      return result;
  
  }
  
  private JobParameters getJobParameters(@Valid @RequestBody JobParam jobParam) {
  
      Map&lt;String, JobParameter&gt; parametermap = new HashMap&lt;&gt;();
      parametermap.put(BatchConstants.PERIOD_START, new JobParameter(jobParam.getPeriodStart()));
      parametermap.put(BatchConstants.PERIOD_END, new JobParameter(jobParam.getPeriodEnd()));
      return new JobParameters(parametermap);
  }
  
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Error creating bean with name 'demandeWebbatchControler': Unsatisfied dependency expressed through field 'jobLauncher'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobLauncher' defined in com.transactis.qpt.parctis.batch.config.IntegrationConfig: Unsatisfied dependency expressed through method 'jobLauncher' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available: expected single matching bean but found 2: threadPoolTaskExecutor,taskScheduler
  </code></pre>