Monday, March 9, 2009

Quartz Implementation

1. Implent the batch job you need to run as the class that extends the class: QuartzJobBean implements StatefulJob.
This should override the method executeInternal. This should contain the stuff you need to cron.
2. Define the bean : org.springframework.scheduling.quartz.JobDetailBean
set the property ''jobClass' which it your implementation of cron that you want to run
3. Point the above bean to org.springframework.scheduling.quartz.CronTriggerBean
as the property jobDetail.
Another parameter it takes is the cron string. This is similar to unix cron
4.Place the above bean in the org.springframework.scheduling.quartz.SchedulerFactoryBean.
as content of the property 'trigger'


<bean name="helloWorld" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.test.eip.viva.batch.HelloWorld" />
</bean>
<bean id="helloWorldBatchTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="helloWorld" />
<property name="cronExpression" value="0 * * * * ?" />
</bean>
<bean id="eipSchedulerFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="helloWorldBatchTrigger" />
</list>
</property>
</bean>




If your cron bean requires additional beans. This is the way to inject the bean. Provide the beans required by the jobClass in a jobDataAsMap property

<bean name="helloWorld" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.test.eip.viva.batch.HelloWorld" />
<property name="jobDataAsMap">
<map>
<entry key="message">
<ref bean="messageProvider" />
</entry>
</map>
</property>
</bean>

No comments:

Post a Comment