We have an enterprise application that uses a Quartz Scheduler to invoke CronJobs. Spring has the ability to create the scheduler and invoke the cronjobs via XML configuration, unfortunately, we need our clients to be able to modify these jobs via our application. Also, we want to read & write the jobs from the database using our Hibernate Layer.
So, what we have is Spring set to startup quartz using the xml config, then in our WebContextLoaderListener we have an initialize method which reads the jobs from the DB and creates the CronJobs. The jobs are part of our action layer (old hangover from Struts), and need to call specific methods, so we are trying to manually instantiate MethodInvokingJobDetailFactoryBeans.
Everything seems to startup fine, and we can manipulate the jobs on the fly while persisting the changes to the DB (in case of server restart), but when the scheduler runs, we get a "IllegalArgumentException: Target method must not be non-static without a target" exception.
Any ideas? (Besides, use the examples.. unless you can point me to an example of Sprig creating the jobs by accessing the database via Hibernate Objects)
I figure I'm missing a step in the MethodInvokingJobDetailFactoryBean creation, I just can't figure out what it is...
XML Config:
Code:<bean id="Scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="autoStartup"> <value>false</value> <!-- RuleManager should be the one starting the Scheduler --> </property> <property name="schedulerName"> <value>ACISScheduler</value> </property> <property name="waitForJobsToCompleteOnShutdown"> <value>true</value> </property> </bean>
Job/Trigger Creation:
Code:Scheduler scheduler = SpringContext.getInstance().getScheduler(); List<CronJob> cronJobList = SpringContext.getInstance().getCronJobLogic().list(); try { scheduler.start(); for (CronJob cronJob : cronJobList) { try { MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean(); jobDetail.setTargetMethod(cronJob.getTargetMethod()); jobDetail.setTargetClass(Class.forName(cronJob.getTargetObject())); jobDetail.setName(cronJob.toString()); jobDetail.afterPropertiesSet(); CronTrigger cronTrigger = new CronTrigger(cronJob.getTriggerName(), cronJob.getGroupName(), cronJob.getExpression()); scheduler.scheduleJob((JobDetail)jobDetail.getObject(), cronTrigger); } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch(SchedulerException se) { logger.error(se.getMessage(), se); }
Thanks,
/Christien


Reply With Quote
