前言:
主要是添加QrtzManager的监听器,这样才会定时任务执行的时候进行加载执行。只有监听器才会在在cron表达式触发的时候进行监听器执行,监听器是执行定时任务的必要条件,如果这个触发器没有实例化的话,所有的配置都是不生效的!
注入Spring的QrtzManager监听器java代码实现逻辑
import com.core.quartz.QrtzManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
/**
* 系统监听器,添加系统通知任务
*/
@Configuration
public class QuartzListener implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private QrtzManager qrtzManager;
private static final String jobGroupName = "tbm_job_group";
private static final String triggerGroupName = "tbm_trigger_group";
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
qrtzManager.addJob(BusinessRelationCacheJob.class,"0 0/30 * * * ?");
qrtzManager.addJob(EventGenerateJob.class, "0 */51 * * * ? ", "EventGenerateJob", jobGroupName,
"EventGenerateTrigger", triggerGroupName, "", null);
qrtzManager.addJob(SyncCompanyZczjToEsJob.class, "0 05 20 * * ? ", "SyncCompanyZczjToEsJob",
jobGroupName, "SyncCompanyZczjToEsTrigger", triggerGroupName,
"同步公司信息中的注册资金到ES", null);
qrtzManager.addJob(TranskerTaskStatusJob.class, "0 3 21 * * ? ", "TranskerTaskStatusJob",
jobGroupName, "TranskerTaskStatusTrigger", triggerGroupName,
"终止时间到期的任务", null);
qrtzManager.addJob(MeetingGenerateJob.class, "0 0/5 * * * ? ", "MeetingGenerateJob", jobGroupName,
"MeetingGenerateTrigger", triggerGroupName, "", null);
}
}