PDA

View Full Version : MethodInvokingJobDetailFactoryBean doesn't extends JobDetail



Samaritan
Nov 24th, 2006, 10:36 AM
Hi,

I'm trying to cofigure job (using Quartz) on String 2.0 RC2.

I wrote the conf following the docs. Here my xml:


<bean id="emailDownloadJob" class="org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean">
<property name="targetObject" ref="emailManager" />
<property name="targetMethod" value="readAccounts" />
</bean>
<bean id="emailDownloadTrigger" class="org.springframework.scheduling.quartz.SimpleTrigge rBean">
<property name="jobDetail" ref="emailDownloadJob" />
<property name="startDelay" value="10000" />
<property name="repeatInterval" value="60000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFac toryBean" autowire="no">
<property name="triggers">
<list>
<ref bean="emailDownloadTrigger" />
</list>
</property>
</bean>

But this doen't works:



2006-11-24 16:01:02,754 - ERROR - org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFa ctoryBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.lang.NullPointerException]
Caused by:
org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.lang.NullPointerException]
at org.springframework.scheduling.quartz.SchedulerFac toryBean.registerJobsAndTriggers(SchedulerFactoryB ean.java:766)
at org.springframework.scheduling.quartz.SchedulerFac toryBean.afterPropertiesSet(SchedulerFactoryBean.j ava:570)



This happens because string doesn't set the trigger jobDetail property but, how it can if MethodInvokingJobDetailFactoryBean doen's extends JobDetail ?

Can someone give me some info ?

Thx in advance,
Fabio

karldmoore
Nov 25th, 2006, 07:47 AM
I MethodInvokingJobDetailFactoryBean example from the reference manual works fine on my machine. Give that a try.

http://www.springframework.org/docs/reference/scheduling.html#d0e27653

Samaritan
Nov 27th, 2006, 07:29 AM
I either used the example strutcure o my app and it doesn't work at all.

I'm tring now v2.0rc4 (instead of rc2) and it seems to work.

karldmoore
Nov 27th, 2006, 07:31 AM
Is using v2.0rc4 a problem, or does it have to be the other version? If your problems fixed.

Samaritan
Nov 27th, 2006, 08:09 AM
v2.0rc4 is ok for me....i updated String today and now my job is working fine.

Arthur Loder
Nov 27th, 2006, 08:11 AM
This happens because string doesn't set the trigger jobDetail property but, how it can if MethodInvokingJobDetailFactoryBean doen's extends JobDetail ?

Not sure that I 100% understand your question with the string, but though the MethodInvokingJobDetailFactoryBean (http://www.springframework.org/docs/api/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.html) does not extend JobDetail, it implements the special FactoryBean (http://www.springframework.org/docs/api/org/springframework/beans/factory/FactoryBean.html) interface. This means that the result of the FactoryBean.getObject (http://www.springframework.org/docs/api/org/springframework/beans/factory/FactoryBean.html#getObject()) call will be returned (or injected) rather than the bean itself.

This section (http://www.springframework.org/docs/reference/beans.html#beans-factory-extension-factorybean) of the Reference manual also explains it.

Glad to hear its working!

n.lakshmanan
May 1st, 2008, 12:04 PM
Hi

I was trying for scheduling a job.
I have done the following...

<bean name="testJob" class="org.springframework.scheduling.quartz.JobDe tailBean">
<property name="jobClass" value="test.TestJob" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
<property name="jobDetail" ref="testJob" />
<!-- run every morning at 6 AM -->
<property name="cronExpression" value="0 0 6 * * ?" />
</bean>

<bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>

package test;

public class TestJob extends QuartzJobBean {

private int timeout;

/**
* Setter called after the ExampleJob is instantiated
* with the value from the JobDetailBean (5)
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}

protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
System.out.println(new Date());
}
}


But my job is not starting........ can anyone help on this?
even i changed this according to my system time...(This following shows everyday 6am)
<property name="cronExpression" value="0 0 6 * * ?" />

Thanks and advance...

n.lakshmanan
May 1st, 2008, 01:38 PM
Hi
I solved it myself
need to put jta.jar and apache commons.jar file in the lib folder
Regards
Laks

n.lakshmanan
May 1st, 2008, 02:45 PM
Hi all,

How do i inject an object in a scheduler?

Regards
Laks

lucasward
May 1st, 2008, 03:56 PM
I'm not sure I understand the question, what do you mean by 'inject an object into a scheduler'?

n.lakshmanan
May 1st, 2008, 03:59 PM
I solved it myself
here is the sample.....

<bean name="emailToSubscriber" class="org.springframework.scheduling.quartz.JobDetailBea n">
<property name="jobClass" value="example.exampleEmailScheduler"/>
<property name="jobDataAsMap">
<map>
<entry key="news">
<ref bean="dailyNews"/>
</entry>
</map>
</property>
</bean>

n.lakshmanan
May 1st, 2008, 04:00 PM
I solved it myself
here is the sample.....

<bean name="emailToSubscriber" class="org.springframework.scheduling.quartz.JobDe tailBean">
<property name="jobClass" value="example.exampleEmailScheduler"/>
<property name="jobDataAsMap">
<map>
<entry key="news">
<ref bean="dailyNews"/>
</entry>
</map>
</property>
</bean>