2016-06-09 184 views
1

我試圖開發一個集成Quartz和彈簧批次的彈簧應用程序。出於某些原因,我無法正確運行它並收到一些編譯錯誤。石英+春季批次彈簧開機

代碼:

QuartzConfiguration 

@Configuration 
@ComponentScan("com.concretepage") 
public class QuartzConfiguration { 

    @Bean 
    public MethodInvokingJobDetailFactoryBean methodInvokingJobDetailFactoryBean() { 
     MethodInvokingJobDetailFactoryBean obj = new MethodInvokingJobDetailFactoryBean(); 
     obj.setTargetBeanName("jobone"); 
     obj.setTargetMethod("myTask"); 
     return obj; 
    } 

    @Bean 
    public CronTriggerFactoryBean cronTriggerFactoryBean(){ 
     CronTriggerFactoryBean stFactory = new CronTriggerFactoryBean(); 
     SpringBatchJobs batch = new SpringBatchJobs(); 
     stFactory.setJobDetail(batch.job()); // here i'm getting some compilcation error like "The method job() from the type SpringBatchJobs refers to the missing type Job" 
     stFactory.setStartDelay(3000); 
     stFactory.setName("mytrigger"); 
     stFactory.setGroup("mygroup"); 
     stFactory.setCronExpression("0/1 * * * * ?"); 
     return stFactory; 
    } 

    @Bean 
    public SchedulerFactoryBean schedulerFactoryBean() { 
     SchedulerFactoryBean scheduler = new SchedulerFactoryBean(); 
     scheduler.setTriggers(cronTriggerFactoryBean().getObject()); 
     return scheduler; 
    } 
} 

Spring Batch的:

@EnableBatchProcessing 
public class SpringBatchJobs { 

    @Autowired 
    private JobBuilderFactory jobs; 

    @Autowired 
    private StepBuilderFactory steps; 

    @Bean 
    protected Tasklet tasklet() { 

     return new Tasklet() { 
      @Override 
      public RepeatStatus execute(StepContribution contribution, 
        ChunkContext context) { 
       return RepeatStatus.FINISHED; 
      } 
     }; 

    } 

    @Bean 
    public Job job() throws Exception { 
     return this.jobs.get("job").start(step1()).build(); 
    } 

    @Bean 
    protected Step step1() throws Exception { 
     return this.steps.get("step1").tasklet(tasklet()).build(); 
    } 

} 

問題來在下一行

stFactory.setJobDetail(batch.job()); // here i'm getting some compilcation error like "The method job() from the type SpringBatchJobs refers to the missing type Job" 

如何運行春季批處理作業春季開機使用Quartz2?任何想法

回答