continuing with the porting of an old web app (written with struts1) to wicket+spring
where quartz was used for scheduling of exports & users update from LDAP to the database
my initial idea was to implement org.quartz.Job interface using a 'service' that does the actual export; these all ended to the service reference remain not initialized; all attempts to 'inject the dependency' failed.
final solution - using spring-context-support
(maven:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
)
then in applicationContext.xml:
<!-- quartz scheduler related -->
<!-- jobs definitions -->
<bean id="export2StatisticsJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"><ref bean="scheduledexportservice"/></property>
<property name="targetMethod"><value>executeScheduledExportsIfAny</value></property>
</bean>
<!-- cron trigger definitions -->
<bean id="export2StatisticsTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="export2StatisticsJob" />
<!-- run every day 5 minutes -->
<property name="cronExpression" value="0 0/5 * * * ?" />
</bean>
<!-- scheduler -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="export2StatisticsTriggerBean" />
</list>
</property>
</bean>
the key here is passing service bean scheduledexportservice as a value of targetObject property in export2StatisticsJob bean definition
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment