Quartz + Spring Batch ในรองเท้าสปริง

ฉันกำลังพยายามพัฒนาแอปพลิเคชันสปริงซึ่งมีการรวม Quartz และ Spring Batch ด้วยเหตุผลบางประการ ฉันไม่สามารถรันได้อย่างถูกต้องและได้รับข้อผิดพลาดในการคอมไพล์

รหัส:

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;
    }
}  

ชุดสปริง:

@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"

ฉันจะรันงาน Spring Batch โดยใช้ Quartz2 ใน spring boot ได้อย่างไร ไอเดียอะไรก็ได้


person user1030128    schedule 09.06.2016    source แหล่งที่มา


คำตอบ (1)


ต้องเปิดตัวงานแบตช์สปริงโดยใช้ตัวเรียกใช้งานแบตช์สปริง

โปรดดูลิงค์ด้านล่างสำหรับรายละเอียดที่แน่นอนเกี่ยวกับวิธีการดำเนินการ

https://examples.javacodegeeks.com/enterprise-java/spring/batch/quartz-spring-batch-example/

person Sushil Behera    schedule 16.12.2017