I finally figured out a way to achieve injecting a ServletContext object onto a quartz scheduler. I had to go about it in a slight different fashion but the end result is the same.
As Marten indicated above, my first problem was that I never established the MoreResourcesProcessor as a spring bean so this was the first requirement:
Code:
<bean id="MoreResourcesProcessor" class="com.soundstrue.mobile.processor.MoreResourcesProcessor">
<property name="s3Svc" ref="s3Svc"/>
<property name="xStreamMarshaller" ref="xStreamMarshaller"/>
</bean>
The MoreResourcesProcessor is now a simple java class which just implements ServletContextAware (no longer extending QuartzJobBean or implementing StatefulJob). The work is now done in the process() method which is completely an arbitrary name. Here is a short snippet of the class for reference:
Code:
public class MoreResourcesProcessor implements ServletContextAware {
.... // members omitted
protected void process() {
// performs all business logic and sets an attribute on the ServletContext which is injected
servletContext.setAttribute("foo", "foo");
}
public void setxStreamMarshaller(XStreamMarshaller xStreamMarshaller) {
this.xStreamMarshaller = xStreamMarshaller;
}
public void setS3Svc(STS3Service s3Svc) {
this.s3Svc = s3Svc;
}
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
}
Then instead of using a JobDetailBean object to declare/configure the jobDetail, I simply use a MethodInvokingJobDetailFactoryBean.
Code:
<bean id="moreResourcesJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="MoreResourcesProcessor"/>
<property name="targetMethod" value="process"/>
<property name="concurrent" value="false"/>
</bean>
<!--http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger-->
<bean id="moreResourcesCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="moreResourcesJobDetail"/>
<property name="cronExpression" value="0 0/2 * * * ?"/><!-- will trigger every 2 minutes -->
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="moreResourcesCronTrigger"/>
</list>
</property>
<property name="quartzProperties">
<util:properties>
<!-- http://forums.terracotta.org/forums/posts/list/3395.page -->
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
</util:properties>
</property>
</bean>
Hope this helps the next person that runs into a similar issue.