mirror of https://github.com/elunez/eladmin
pull/702/head
parent
7167f29276
commit
08f6c58211
|
@ -15,13 +15,10 @@
|
|||
*/
|
||||
package me.zhengjie.modules.quartz.config;
|
||||
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.spi.TriggerFiredBundle;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
@ -46,27 +43,10 @@ public class QuartzConfig {
|
|||
|
||||
@Override
|
||||
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||
|
||||
//调用父类的方法
|
||||
//调用父类的方法,把Job注入到spring中
|
||||
Object jobInstance = super.createJobInstance(bundle);
|
||||
capableBeanFactory.autowireBean(jobInstance);
|
||||
return jobInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入scheduler到spring
|
||||
* @param quartzJobFactory /
|
||||
* @return Scheduler
|
||||
* @throws Exception /
|
||||
*/
|
||||
@Bean(name = "scheduler")
|
||||
public Scheduler scheduler(QuartzJobFactory quartzJobFactory) throws Exception {
|
||||
SchedulerFactoryBean factoryBean=new SchedulerFactoryBean();
|
||||
factoryBean.setJobFactory(quartzJobFactory);
|
||||
factoryBean.afterPropertiesSet();
|
||||
Scheduler scheduler=factoryBean.getScheduler();
|
||||
scheduler.start();
|
||||
return scheduler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.quartz.domain.QuartzJob;
|
||||
import org.quartz.*;
|
||||
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
@ -35,7 +36,7 @@ public class QuartzManage {
|
|||
|
||||
private static final String JOB_NAME = "TASK_";
|
||||
|
||||
@Resource(name = "scheduler")
|
||||
@Resource
|
||||
private Scheduler scheduler;
|
||||
|
||||
public void addJob(QuartzJob quartzJob){
|
||||
|
|
Loading…
Reference in New Issue