title: JobLauncherTestUtils throws NoUniqueBeanDefinitionException while trying to test spring batch steps
body: <p>I am using Spring boot and Spring batch. I have defined more than one job. </p>
  
  <p>I am trying to build junit to test specific task within a job.</p>
  
  <p>Therefor I am using the JobLauncherTestUtils library.</p>
  
  <p>When I run my test case I always get NoUniqueBeanDefinitionException.</p>
  
  <p>This is my test class:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringApplicationConfiguration(classes = {BatchConfiguration.class})
  public class ProcessFileJobTest  {
  
      @Configuration
      @EnableBatchProcessing
      static class TestConfig {
          @Autowired
  
          private JobBuilderFactory jobBuilder;
          @Autowired
          private StepBuilderFactory stepBuilder;
  
          @Bean
          public JobLauncherTestUtils jobLauncherTestUtils() {
              JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
              jobLauncherTestUtils.setJob(jobUnderTest());
              return jobLauncherTestUtils;
          }
  
  
          @Bean
          public Job jobUnderTest() {
              return jobBuilder.get("job-under-test")
                      .start(processIdFileStep())
                      .build();
          }
  
  
          @Bean
          public Step processIdFileStep() {
              return stepBuilder.get("processIdFileStep")
                      .&lt;PushItemDTO, PushItemDTO&gt;chunk(1) //important to be one in this case to commit after every line read
                      .reader(reader(null))
  
                      .processor(processor(null, null, null, null))
                      .writer(writer())
  
                              //     .faultTolerant()
                              //   .skipLimit(10) //default is set to 0
                              //     .skip(MySQLIntegrityConstraintViolationException.class)
                      .build();
          }
  
  
          @Bean
          @Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES)
          public ItemStreamReader&lt;PushItemDTO&gt; reader(@Value("#{jobExecutionContext[filePath]}") String filePath) {
              ...
              return itemReader;
          }
  
          @Bean
          @Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES)
          public ItemProcessor&lt;PushItemDTO, PushItemDTO&gt; processor(@Value("#{jobParameters[pushMessage]}") String pushMessage,
                                                                   @Value("#{jobParameters[jobId]}") String jobId,
                                                                   @Value("#{jobParameters[taskId]}") String taskId,
                                                                   @Value("#{jobParameters[refId]}") String refId)
          {
              return new PushItemProcessor(pushMessage,jobId,taskId,refId);
          }
  
          @Bean
          public LineMapper&lt;PushItemDTO&gt; lineMapper() {
              DefaultLineMapper&lt;PushItemDTO&gt; lineMapper = new DefaultLineMapper&lt;PushItemDTO&gt;();
             ...
              return lineMapper;
          }
  
          @Bean
          public ItemWriter writer() {
              return new someWriter();
          }
      }
  
  
      @Autowired
      protected JobLauncher jobLauncher;
  
      @Autowired
      JobLauncherTestUtils jobLauncherTestUtils;
  
  
  
      @Test
      public void processIdFileStepTest1() throws Exception {
          JobParameters jobParameters = new JobParametersBuilder().addString("filePath", "C:\\etc\\files\\2015_02_02").toJobParameters();
          JobExecution jobExecution = jobLauncherTestUtils.launchStep("processIdFileStep",jobParameters);
  
      }
  </code></pre>
  
  <p>and thats the exception:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.Job] is defined: expected single matching bean but found 3: jobUnderTest,executeToolJob,processFileJob
  </code></pre>
  
  <p>Any idea? 
  Thanks.</p>
  
  <p>added BatchConfiguration class:</p>
  
  <pre><code>package com.mycompany.notification_processor_service.batch.config;
  
  import com.mycompany.notification_processor_service.common.config.CommonConfiguration;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.*;
  import org.springframework.jdbc.core.JdbcTemplate;
  import org.springframework.jdbc.datasource.DriverManagerDataSource;
  
  import javax.sql.DataSource;
  
  
  @ComponentScan("com.mycompany.notification_processor_service.batch")
  @PropertySource("classpath:application.properties")
  @Configuration
  @Import({CommonConfiguration.class})
  @ImportResource({"classpath:applicationContext-pushExecuterService.xml"/*,"classpath:si/integration-context.xml"*/})
  public class BatchConfiguration {
  
      @Value("${database.driver}")
      private String databaseDriver;
      @Value("${database.url}")
      private String databaseUrl;
      @Value("${database.username}")
      private String databaseUsername;
      @Value("${database.password}")
      private String databasePassword;
  
  
  
      @Bean
      public DataSource dataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(databaseDriver);
          dataSource.setUrl(databaseUrl);
          dataSource.setUsername(databaseUsername);
          dataSource.setPassword(databasePassword);
          return dataSource;
      }
  
      @Bean
      public JdbcTemplate jdbcTemplate(DataSource dataSource) {
          return new JdbcTemplate(dataSource);
      }
  
  }
  </code></pre>
  
  <p>and this is CommonConfiguration</p>
  
  <pre><code>@ComponentScan("com.mycompany.notification_processor_service")
  @Configuration
  @EnableJpaRepositories(basePackages = {"com.mycompany.notification_processor_service.common.repository.jpa"})
  @EnableCouchbaseRepositories(basePackages = {"com.mycompany.notification_processor_service.common.repository.couchbase"})
  @EntityScan({"com.mycompany.notification_processor_service"})
  @EnableAutoConfiguration
  @EnableTransactionManagement
  @EnableAsync
  public class CommonConfiguration {
  
  }
  </code></pre>