1

Hi I have created a cron job and its working well by using

org.springframework.scheduling.quartz.SimpleTriggerBean

but when I schedule my job using CronTrigger the job didnt trigger at all neither it throw any error below is my spring config and Job class.

<bean id="cronJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="runBillingJob" />
        <property name="cronExpression" value="0 0 0 * * ?"/>
</bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails">
            <list>
                <ref bean="runTestJob" />
            </list>
        </property>

        <property name="triggers">
            <list>
                <ref bean="cronJobTrigger" />
            </list>
        </property>
    </bean>

following is my Test method:

@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context)
        throws JobExecutionException {
    List<JobExecutionContext> jobs = null;
    try {
        jobs = context.getScheduler().getCurrentlyExecutingJobs();
        for (JobExecutionContext job : jobs) {
            if (job.getTrigger().equals(context.getTrigger())
                    && !job.getJobInstance().equals(this)) {
                logger.trace("There's another instance running, so leaving: "
                        + this);
                return;
            }
        }
        logger.info("Create a BillingService instance...");

    } catch (SchedulerException e) {
        logger.error("", e);
        return;
    }

    try {
        triggerToController();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
darrenmc
  • 1,721
  • 1
  • 19
  • 29
Talha Bin Shakir
  • 2,563
  • 10
  • 38
  • 54
  • I assume you have invoked start on SchedulerFactoryBean and waited until midnight for your cron expression to trigger? – darrenmc Oct 08 '13 at 15:06
  • You have a reference to runBillingJob but I cannot see where it is defined. See my answer below. – L. Holanda Oct 17 '13 at 23:04

1 Answers1

0

Try this:

    <bean id="cronJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="runBillingJob" />
        <property name="cronExpression" value="0 0 0 * * ?"/>
    </bean>
    <bean id="runBillingJob" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="your.package.YourClass" />
    </bean>
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronJobTrigger" />
            </list>
        </property>
    </bean>
L. Holanda
  • 4,432
  • 1
  • 36
  • 44