title: Autowiring in Quartz multiple Jobs with Spring Boot not working
body: <p>I'm try to use quartz scheduler in spring. I get below exception when configuring multiple jobs  </p>
  
  <blockquote>
    <p>Parameter 0 of method jobTrigger in Job2 required a bean of type 'org.quartz.JobDetail' that could not be found.</p>
  </blockquote>
  
  <p>quartz - v2.3, Spring - v4.2.x</p>
  
  <p>Config Class</p>
  
  <pre><code>@Configuration
   public class SchedulerConfig {
  
  private static final Logger LOG = LoggerFactory.getLogger(SchedulerConfig.class);
  
  @Autowired
  List&lt;Trigger&gt; triggers;
  
  @Bean
  public JobFactory jobFactory(ApplicationContext applicationContext) {
      AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
      jobFactory.setApplicationContext(applicationContext);
      return jobFactory;
  }
  
  @Bean
  public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory)  throws IOException {
      SchedulerFactoryBean factory = new SchedulerFactoryBean();
            factory.setAutoStartup(true);
      factory.setJobFactory(jobFactory);
           factory.setQuartzProperties(quartzProperties());
      if (triggers != null &amp;&amp; !triggers.isEmpty()) {
           LOG.info("starting jobs... Total Triggers - " + triggers.size());
          factory.setTriggers(triggers.toArray(new Trigger[triggers.size()]));
      }
  
      return factory;
  }
  
  @Bean
  public Properties quartzProperties() throws IOException {
      PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
      propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
      propertiesFactoryBean.afterPropertiesSet();
      return propertiesFactoryBean.getObject();
  }
  
  
  public static CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression) {
      CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
      factoryBean.setJobDetail(jobDetail);
      factoryBean.setCronExpression(cronExpression);
      factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
      return factoryBean;
  }
  
  public static JobDetailFactoryBean createJobDetail(Class jobClass) {
      JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
      factoryBean.setJobClass(jobClass);
      factoryBean.setDurability(true);
      return factoryBean;
  }
  </code></pre>
  
  <p>SpringBeanJobFactory</p>
  
  <pre><code>public final class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
  
  private static final Logger LOG = LoggerFactory.getLogger(AutowiringSpringBeanJobFactory.class);
  
  private transient AutowireCapableBeanFactory beanFactory;
  
  @Override
  public void setApplicationContext(final ApplicationContext context) {
      beanFactory = context.getAutowireCapableBeanFactory();
  }
  
  @Override
  protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
      final Object job = super.createJobInstance(bundle);
      LOG.info("create job instance");
      beanFactory.autowireBean(job);
      return job;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Job 1</p>
  
  <pre><code>@Component
  @DisallowConcurrentExecution
  public class Job1 implements Job {
  
  private final Logger log = LoggerFactory.getLogger(this.getClass());
  
  @Value("${schedule}")
  private String frequency;
  
  @Autowired
  private Service service;
  
  @Override
  public void execute(JobExecutionContext jobExecutionContext) {
      log.info("execute");
  }
  
  @Bean(name = "jobBean1")
  public JobDetailFactoryBean job() {
      return SchedulerConfig.createJobDetail(this.getClass());
  }
  
  @Bean(name = "jobBean1Trigger")
  public CronTriggerFactoryBean jobTrigger(@Qualifier("jobBean1")JobDetail jobDetail) {
      return SchedulerConfig.createCronTrigger(jobDetail, frequency);
  }
  </code></pre>
  
  <p>Job 2</p>
  
  <pre><code>@Component
  @DisallowConcurrentExecution
  public class Job2 implements Job {
  
  private final Logger log = LoggerFactory.getLogger(this.getClass());
  
  @Value("${schedule}")
  private String frequency;
  
  @Autowired
  private Service service;
  
  @Override
  public void execute(JobExecutionContext jobExecutionContext) {
      log.info("execute");
  }
  
  @Bean(name = "jobBean2")
  public JobDetailFactoryBean job() {
      return SchedulerConfig.createJobDetail(this.getClass());
  }
  
  @Bean(name = "jobBean2Trigger")
  public CronTriggerFactoryBean jobTrigger(@Qualifier("jobBean2")JobDetail jobDetail) {
      return SchedulerConfig.createCronTrigger(jobDetail, frequency);
  }
  </code></pre>
  
  <p>The Service class has Spring JPA repos.
  The root cause of the problem is the below autowired service. If I remove the below autowired service from both the jobs, it works fine.</p>
  
  <blockquote>
    <p>@Autowired
      private Service service;</p>
  </blockquote>
  
  <p>If there is only one job with this autowired bean, then there is no exception.
  How to configure multiple jobs using the same autowired dependency? 
  What is cause this issue?</p>