title: Autowire spring data with quartz
body: <p>I'm work on spring project using jparepository and quartz scheduler,I use the following configuration class to autowire spring data with quartz ,this configuration class works well and fire job once I run project with no errors,But I want to fire jobs manually by the following spring controller but I got @autowire error with spring data</p>
  
  <p>Quartz Job</p>
  
  <pre><code>@Service
  @Transactional
  public class JobOne implements Job{
  
  @Autowired
  TestrecordRepository testrecordRepository;
  @Autowired
  ScoreRepository scoreRepository;
  
  
  public void execute(JobExecutionContext context)
          throws JobExecutionException {
              System.out.println("Job one!"); 
              List&lt;Testrecord&gt; records=testrecordRepository.findAll();
              for(Testrecord t:records){
                  Testrecord testrecord = new Testrecord();
                  testrecord.setValue_integer(t.getValue_integer());
                  testrecord.setId(t.getId());
                  RuleExecutor ruleExecutor = new RuleExecutor();
                  Score score= ruleExecutor.processRules(testrecord);
                  scoreRepository.save(score);    
              }
  
          }
       }
  </code></pre>
  
  <p>configuration class </p>
  
  <pre><code>@Configuration
  public class QuartzConfig {
  
  @Autowired
  private ApplicationContext applicationContext;
  
  @Bean
  public SchedulerFactoryBean quartzSchedulerjobOne() {
      SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
  
      quartzScheduler.setOverwriteExistingJobs(true);
  
      AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
      jobFactory.setApplicationContext(applicationContext);
      quartzScheduler.setJobFactory(jobFactory);
  
      Trigger[] triggers = {
              processjobOneTrigger().getObject()
      };
  
      quartzScheduler.setTriggers(triggers);
  
      return quartzScheduler;
  }
  
  @Bean
  public JobDetailFactoryBean processjobOne() {
      JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
      jobDetailFactory.setJobClass(JobOne.class);
      jobDetailFactory.setDurability(true);
      return jobDetailFactory;
  }
  
  @Bean
  public CronTriggerFactoryBean processjobOneTrigger() {
      CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
      cronTriggerFactoryBean.setJobDetail(processjobOne().getObject());
      cronTriggerFactoryBean.setCronExpression("0 0/1 * * * ?");
      return cronTriggerFactoryBean;
  }
  </code></pre>
  
  <p>Spring controller</p>
  
  <pre><code>     @RequestMapping(value = "/test",
          method = RequestMethod.GET)
  public void test(HttpServletRequest request) throws Exception{
      ApplicationContext context = new AnnotationConfigApplicationContext(
              QuartzConfig.class);
      Scheduler scheduler = (Scheduler)context.getBean("quartzSchedulerjobOne");
  
  }
  </code></pre>
  
  <p>eclipse console</p>
  
  <pre><code>       org.quartz.SchedulerException: Job instantiation failed
  at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:45) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) ~[quartz-2.1.5.jar:na]
  at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:387) [quartz-2.1.5.jar:na]
  
         Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.innvo.quartz.JobOne': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobOne.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBean(AbstractAutowireCapableBeanFactory.java:302) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at com.innvo.quartz.AutowiringSpringBeanJobFactory.createJobInstance(AutowiringSpringBeanJobFactory.java:22) ~[classes/:na]
  at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:41) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 2 common frames omitted
      Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobOne.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 6 common frames omitted
      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 8 common frames omitted
     [ERROR] org.quartz.core.ErrorLogger - An error occured instantiating job to be executed. job= 'DEFAULT.processJobTwo'
    org.quartz.SchedulerException: Job instantiation failed
  at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:45) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) ~[quartz-2.1.5.jar:na]
  at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:387) [quartz-2.1.5.jar:na]
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.innvo.quartz.JobTwo': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBean(AbstractAutowireCapableBeanFactory.java:302) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at com.innvo.quartz.AutowiringSpringBeanJobFactory.createJobInstance(AutowiringSpringBeanJobFactory.java:22) ~[classes/:na]
  at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:41) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 2 common frames omitted
     Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 6 common frames omitted
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  ... 8 common frames omitted
  </code></pre>