我正在使用 Spring 注释来连接我的应用程序依赖项。
据我所知,没有办法将我的 JobListener 注入 Quartz SchedulerFactoryBean,因为它是在此处配置的:
@Bean(name="schedulerFactory")
public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setApplicationContextSchedulerContextKey("applicationContext");
schedulerFactoryBean.setConfigLocation(new ClassPathResource("quartz.properties"));
schedulerFactoryBean.setDataSource(dataSource);
// This call results in the error:
// java.lang.IllegalStateException: Non-global JobListeners not supported on
// Quartz 2 - manually register a Matcher against the Quartz ListenerManager instead
//schedulerFactoryBean.setJobListeners(new JobListener[] { jobActivityListener() });
return schedulerFactoryBean;
}
我目前必须以编程方式配置首次触发作业时要创建的 JobListener:
ListenerManager listenerManager = scheduler.getListenerManager();
if (listenerManager.getJobListener(jobKey.getName()) == null) {
logger.debug("ADDING JOB LISTENER FOR " + jobKey.getName());
listenerManager.addJobListener(new JobActivityListener(), keyEquals(jobKey));
}
这并不理想,因为我们希望 Spring 管理依赖项,并注入 JobListener 所需的依赖项。
有没有关于通过 Spring 配置作业侦听器的信息?