title: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be
body: <p>I am using the <strong>spring batch boot example</strong>. In my project, I have two batch jobs developed so far and in future will be having around 10 batch jobs running simultaneously. </p>
  
  <p>I developed the code for the second batch job and when I started to run the 2nd batch job, I started getting the below error.</p>
  
  <p>I have following doubts in my mind - </p>
  
  <ol>
  <li>How can I run only 2nd batch for my development and unit testing ?</li>
  <li>How can I run all the batch jobs in one go ?</li>
  </ol>
  
  <p>Error which is coming - </p>
  
  <pre><code>org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.batch.core.Job' available: expected single matching bean but found 2: exportemployeesJob,exportOrdersJob
      at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:215) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
      at com.prateek.SpringBatchClassicDbApplication.main(SpringBatchClassicDbApplication.java:12) [classes/:na]
  
  2018-07-08 21:45:23.396 ERROR 11600 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field job in com.prateek.scheduler.EmployeesRunScheduler required a single bean, but 2 were found:
      - exportemployeesJob: defined by method 'exportemployeesJob' in class path resource [com/prateek/job/EmployeesJob.class]
      - exportOrdersJob: defined by method 'exportOrdersJob' in class path resource [com/prateek/job/OrdersJob.class]
  
  
  Action:
  
  Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
  </code></pre>
  
  <p><strong>OrdersJob.java</strong></p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class OrdersJob {
  
      @Autowired
      private JobBuilderFactory jobBuilderFactory;
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Autowired
      private DataSource dataSource;
  
      @Bean(destroyMethod="")
      public JdbcCursorItemReader&lt;Orders&gt; ordersReader(){
          JdbcCursorItemReader&lt;Orders&gt; itemReader = new JdbcCursorItemReader&lt;&gt;();
          itemReader.setDataSource(dataSource);
          itemReader.setSql("SELECT orderNumber, productName, msrp, priceEach "
                  + "FROM products p "
                  + "INNER JOIN orderdetails o "
                  + "ON p.productcode = o.productcode "
                  + "AND p.msrp &gt; o.priceEach ");
                  //+ "WHERE p.productcode = ? ");
          itemReader.setRowMapper(new OrdersRowMapper());
          itemReader.setIgnoreWarnings(true);
  
          return itemReader;
      }
  
  
      @Bean(destroyMethod="")
      public FlatFileItemWriter&lt;Orders&gt; ordersWriter(){
          FlatFileItemWriter&lt;Orders&gt; fileItemWriter = new FlatFileItemWriter&lt;&gt;();
          fileItemWriter.setResource(new FileSystemResource("csv/Orders.csv"));
          //fileItemWriter.setHeaderCallback(headerCallback());
  
          DelimitedLineAggregator&lt;Orders&gt; lineAggregator = new DelimitedLineAggregator&lt;&gt;();
          lineAggregator.setDelimiter(",");
          lineAggregator.setFieldExtractor(new PassThroughFieldExtractor&lt;Orders&gt;());
  
          fileItemWriter.setLineAggregator(lineAggregator);
          fileItemWriter.setShouldDeleteIfEmpty(true);
  
          return fileItemWriter;
      }
  
  
      // Step Execution
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .&lt;Orders, Orders&gt;chunk(10)
                  .reader(ordersReader())
                  .writer(ordersWriter())
                  .build();
      }
  
      // Job Execution
      @Bean
      public Job exportOrdersJob() {
          return jobBuilderFactory
                  .get("exportOrdersJob")
                  .incrementer(new RunIdIncrementer())
                  .flow(step1())
                  .end()
                  .build();
      }
  }
  </code></pre>
  
  <p><strong>EmployeesJob.java</strong></p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class EmployeesJob {
      public static final String DATE_FORMAT = "dd-MM-yyyy-hh-mm-ssss";
      public static final DateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
  
      @Autowired
      private JobBuilderFactory jobBuilderFactory;
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Autowired
      private DataSource dataSource;
  
      @Bean 
      public EmployeesProcessor employeesProcessor() {
          return new EmployeesProcessor();
      }
  
      @Bean
      public EmployeesRunScheduler scheduler() {
          return new EmployeesRunScheduler();
      }
  
      // This file helps to create CSV column aliases
      @Bean
      public EmployeesFlatFileWriterCallback headerCallback() {
          return new EmployeesFlatFileWriterCallback();
      }
  
      @Bean(destroyMethod="")
      public JdbcCursorItemReader&lt;Employees&gt; employeesReader(){
          JdbcCursorItemReader&lt;Employees&gt; itemReader = new JdbcCursorItemReader&lt;&gt;();
          itemReader.setDataSource(dataSource);
          itemReader.setSql("SELECT employeeNumber, lastName, firstName, extension, email, officeCode, reportsTo, jobTitle FROM employees ");
          itemReader.setRowMapper(new EmployeeRowMapper());
          // The fetch size can be controlled from the application.properties 
          //itemReader.setFetchSize(200);
          return itemReader;
      }
  
  
      @Bean(destroyMethod="")
      public FlatFileItemWriter&lt;Employees&gt; employeesWriter(){
          FlatFileItemWriter&lt;Employees&gt; fileItemWriter = new FlatFileItemWriter&lt;&gt;();
          //fileItemWriter.setResource(new FileSystemResource("csv/employees.csv"));
          fileItemWriter.setResource(new FileSystemResource("csv/employees-#{"+ formatter.format(new Date()) +"}.csv"));
          fileItemWriter.setHeaderCallback(headerCallback());
  
          BeanWrapperFieldExtractor&lt;Employees&gt; fieldExtractor = new BeanWrapperFieldExtractor&lt;&gt;();
          fieldExtractor.setNames(new String[] {"employeeNumber", "lastName", "firstName", "extension", "email", "officeCode", "reportsTo", "jobTitle"});
  
          DelimitedLineAggregator&lt;Employees&gt; lineAggregator = new DelimitedLineAggregator&lt;&gt;();
          lineAggregator.setDelimiter(",");
          lineAggregator.setFieldExtractor(fieldExtractor);
  
          fileItemWriter.setLineAggregator(lineAggregator);
          fileItemWriter.setShouldDeleteIfEmpty(true);
  
          return fileItemWriter;
      } 
  
      // Step Execution
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .&lt;Employees, Employees&gt;chunk(10)
                  .reader(employeesReader())
                  .processor(employeesProcessor())
                  .writer(employeesWriter())
                  .build();
      }
  
      // Job Execution
      @Bean
      public Job exportemployeesJob() {
          return jobBuilderFactory
                  .get("employeesJob")
                  .incrementer(new RunIdIncrementer())
                  .flow(step1())
                  .end()
                  .build();
      }
  }
  </code></pre>