Java Reference
In-Depth Information
launch-context.xml
consists mostly of the usual Spring Batch suspects, as shown in Listing 6-12.
You need to add just three beans to make the Quartz interaction work:
jobDetail
,
cronTrigger
, and
schedule
.
Listing 6-12.
Updates to
launch-context.xml
...
<bean id="jobDetail"
class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass"
value="com.apress.springbatch.chapter6.SpringBatchQuartzJobLauncher"/>
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="deleteFilesJob" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
<entry key="jobExplorer" value-ref="jobExplorer"/>
<entry key="jobParameters">
<map>
<entry key="path" value="${batch.temp.dir}" />
<entry key="age" value="${batch.temp.age}" />
</map>
</entry>
</map>
</property>
</bean>
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/10 * * * * ?" />
</bean>
<bean id="schedule"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers" ref="cronTrigger"/>
</bean>
...
The first bean of consequence in
launch-context.xml
for the Quartz example is the
jobDetail
bean.
Here is where you configure
SpringBatchQuartzJobLauncher
. It's important to note how the relationship
between Spring's
JobDetailBean
and the
SpringBatchQuartzJobLauncher
bean is used. You configure a
JobDetailBean
as a Spring bean in
launch-context.xml
. Each time your Quartz job is executed, the
JobDetailBean
creates a new instance of
SpringBatchQuartzJobLauncher
. When configuring the
JobDetailBean
,
jobDetail
, you set two properties:
jobClass
: This is the class that is instantiated and executed each time the Quartz
job runs.
•