我正在尝试使用石英作业调度程序自动发送电子邮件。为此,我使用 jobDataMap 将完成作业所需的数据从初始化 cronTrigger 的类传递到执行作业的类。但是,当我尝试访问应该使用 jobDataMap 传递的数据时,它总是返回 null。任何人都有任何想法可能会出现什么问题?这是我初始化触发器的类中的代码:
trigger = new CronTrigger("SendReportEmailsTrigger", "CronTriggerGroup", "0 0/1 * * * ?");
List < UserDetails> aList = customerDetailsService.getUsersConfiguredForEmailedReports();
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("service", reportService);
trigger.setJobDataMap(jobDataMap);
这是执行作业的代码:
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
logger.debug("map = " + dataMap.entrySet());
logger.debug("dataMap = " + context.getJobDetail().getJobDataMap());
for (Object val : dataMap.entrySet()) {
logger.debug("next data map val = " + val);
}
EmailReportService emailReportService = (EmailReportService) dataMap.get("service");
logger.debug("email report service = " + emailReportService);
在日志中 emailReportService 返回为 null。