SchedulerConfig.java定时任务Job中service注入NullPointerException
[原因]:trigger没有注册,很诡异?没设置时间也运行?
定时任务Job中service注入NullPointerException
[原因]:创建的Service是Quartz管理的,不是Spring,无法注入
Job 是通过反射出来的实例,不受spring的管理
@Autowired
private ApplicationContext applicationContext;
@Bean(name = "scheduler")
public SchedulerFactoryBean schedulerFactoryBean(Trigger trigger) {
SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
// 用于quartz集群,QuartzScheduler启动时更新已存在的job
factoryBean.setOverwriteExistingJobs(true);
// 延时启动,应用启动1秒后
factoryBean.setStartupDelay(1);
// 注册触发器
factoryBean.setTriggers(trigger);
// Spring依赖注入为null
SpringQuartzJobFactory jobFactory = new SpringQuartzJobFactory();
jobFactory.setApplicationC