package org.jeecg.modules.quartz.config;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @desc: 启动程序，初始化任务执行监听
 */
@Component
public class SysJobListenerInit implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private Scheduler scheduler;
    @Autowired
    private SysJobListener sysJobListener;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        try {
            scheduler.getListenerManager().addJobListener(sysJobListener);
        } catch (SchedulerException e) {
            e.printStackTrace();//处理异常
        }
    }
}
