我有一个Web应用程序,我使用spring应用程序上下文来注入我的bean,在我的应用程序中使用@Autowired注释我有一个服务,有一个生成报告的方法,这个服务是这样的:
public ReportingService extends CommonService { //this method is called from a controller to generate a report right now //after filling the parameters of the report i.e. businessday public generateReport(Request request) {.....} public generateScheduledReport() { //read configured parameters from database and fill request Request rr = ...; generateReport(request); }
对于计划的报告,我已经定义了一个扩展QuartzJobBea`的作业,并使用我的ReportingService的一个字段来调用它的generateScheduledReport,如下所示:
public class ScheduledReportJob extends QuartzJobBean { @Autowired @Qualifier("reportScheduler") CommonService reportScheduler; //getters and setters @Override protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException { reportScheduler.generateScheduledReport();
在我的applicationContext中,我按如下方式设置了quartz和spring bean:
applicationContext
我的ReportingService包含对其他bean的引用,这些bean也是通过应用程序上下文注入的.我的问题是调度程序正在运行并已成功启动但是用于调度作业的所有注入bean都被初始化为null,请帮助
在搜索了很多线程和博客之后,我通过以下方式让我的应用程序正常工作:在方法的第一行executeInternal
我放了这一行:
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
我从答案中找到了
然后我启动了应用程序"仍然没有注入bean"但是这样做了quartz将其触发器保存到数据库中,稍后将使用.之后我将这些属性添加到我的作业bean:
<property name="jobDataAsMap"> <map> <entry key="schedulerTask" value-ref="reportWithTWService" /> </map> </property>
一切都很顺利.但是当用石英表添加这些属性时它不起作用,我仍然希望有人能够向我解释发生了什么