I have a web application I use spring application context to inject my beans which is annotated with @Autowired inside my application I have a service that have a method to generate report, this service is like this:
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);
}
for the scheduled report I have defined a job which extends QuartzJobBea` and used a field of my ReportingService to invoke its generateScheduledReport like this:
public class ScheduledReportJob extends QuartzJobBean {
@Autowired
@Qualifier("reportScheduler")
CommonService reportScheduler;
//getters and setters
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
reportScheduler.generateScheduledReport();
in my applicationContext I set quartz and spring beans as follows:
<bean id"reportScheduler" class="com.monim.ReportingService"/>
<bean name="schedulingjob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.monim.ScheduledReportJob " />
<property name="name" value="name" />
<property name="group" value="group"/>
<property name="durability" value="true" />
</bean>
<bean id="trigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="name" />
<property name="group" value="group" />
<property name="jobDetail" ref="schedulingjob" />
<property name="cronExpression" value="0/5 * * * * ?" />
<!-- MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY - SEE MISFIRE INSTRUCTIONS
<property name="misfireInstruction" value="1" />
<bean id="Scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
p:waitForJobsToCompleteOnShutdown="false" lazy-init="true">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="overwriteExistingJobs" value="false" />
<property name="quartzProperties">
<map>
<!-- scheduler configuration -->
<entry key="org.quartz.scheduler.instanceName" value="scheduler" />
<entry key="org.quartz.scheduler.skipUpdateCheck" value="true" />
<entry key="org.quartz.jobStore.misfireThreshold" value="60000" />
<!-- JobStore configuration -->
<entry key="org.quartz.jobStore.class" value="org.quartz.impl.jdbcjobstore.JobStoreCMT" />
<entry key="org.quartz.jobStore.dataSource" value="dataSource" />
<entry key="org.quartz.jobStore.nonManagedTXDataSource" value="quartzDataSource" />
<entry key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.oracle.OracleDelegate"/>
<entry key="org.quartz.jobStore.tablePrefix" value="QRTZ_" />
<entry key="org.quartz.jobStore.useProperties" value="true" />
<entry key="org.quartz.jobStore.selectWithLockSQL"
value="SELECT * FROM {0}LOCKS WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE" />
<entry key="org.quartz.jobStore.isClustered" value="false" />
<!-- ThreadPool configuration -->
<entry key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool" />
<entry key="org.quartz.threadPool.threadCount" value="3" />
</map>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
<property name="jobDetails">
<list>
<ref bean="schedulingjob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="trigger" />
</list>
</property>
</bean>
my ReportingService contains references to other beans which are also injected through application context. My problem is that the scheduler is working and have started successfully but all injected beans used to schedule the job are initialized to null, help please