自定义工厂类
/**
* @ClassName SchedulerFactory
* @Description TODO 自定义工厂类
* @Author lg
* @Date 2019/6/5 14:32
* @Version 1.0
**/
@Component
public class SchedulerFactory extends AdaptableJobFactory {
//spring bean 对象管理工厂
@Autowired
private AutowireCapableBeanFactory capableBeanFactory;
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
//自动注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
}
定时任务配置类
XXXJob类
public class DictionaryJob implements BaseJob {
private static Logger _log = LoggerFactory.getLogger(DictionaryJob.class);
@Autowired
private DictionaryService dictionaryService;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
_log.info("DictionaryJob执行时间: " + new Date());
int i = dictionaryService.getDictionaryList().size();
System.out.println("DictionaryJob定时任务"+i);
}
}