【发布时间】:2015-08-17 14:49:30
【问题描述】:
我有一个 QuartzJobBean,我想从我的 Quartz 作业中访问我的 Spring 应用程序上下文。我按照following blog 上的指示进行操作。但是,以下代码无法正常工作:
private ApplicationContext getApplicationContext(JobExecutionContext context ) throws Exception {
System.err.println("check if variables are null - " + (context.getScheduler().getContext() == null));
System.err.flush();
ApplicationContext appCtx = (ApplicationContext)context.getScheduler().getContext().get(APPLICATION_CONTEXT_KEY);
if (appCtx == null) {
throw new JobExecutionException(
"No application context available in scheduler context for key /"" + APPLICATION_CONTEXT_KEY + "/"");
}
return appCtx;
}
在运行时会打印以下消息:
检查变量是否为空 - 假
调度程序上下文中没有可用的应用程序上下文 “应用上下文”
我对自己可能做错了什么感到有些困惑。我的 Spring 应用程序上下文是否可能未命名为“applicationContext”?如果是这样,spring 应用程序上下文的名称将在哪里配置?关于为什么我的应用程序上下文为空的任何其他想法?
谢谢。
【问题讨论】: