I have a QuartzJobBean implementation that I'm feeding with a JobDetailBean, and according to the docs it should be populating the properties from the map:
Yet, when I execute, nothing is there:Simple implementation of the Quartz Job interface, applying the passed-in JobDataMap and also the SchedulerContext as bean property values. This is appropriate because a new Job instance will be created for each execution. JobDataMap entries will override SchedulerContext entries with the same keys.
For example, let's assume that the JobDataMap contains a key "myParam" with value "5": The Job implementation can then expose a bean property "myParam" of type int to receive such a value, i.e. a method "setMyParam(int)".
2004-08-27 13:52:48,964 [project.subproject.scheduling.AssetSearch.executeI nternal] AssetSearch Executing. . .
2004-08-27 13:52:48,980 [project.subproject.scheduling.AssetSearch.executeI nternal] AssetSearch internals: AssetSearch{millisecondsBetweenJobs=0,appContext=n ull,scheduler=org.quartz.impl.StdScheduler@2091065 3,childJobBeanName='null',myService=null}Code:<bean id="assetSearchDetail" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>project.subproject.scheduling.AssetSearch</value> </property> <property name="jobDataAsMap"> <map> <entry key="childJobBeanName"> <value>stockNumberAssetSearch</value> </entry> <entry key="millisecondsBetweenJobs"> <value>2000</value> </entry> </map> </property> </bean> <bean id="assetSearchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail"> <ref bean="assetSearchDetail"/> </property> <property name="startDelay"> <!-- 10 minutes (600,000 milliseconds) --> <value>0</value> </property> <property name="repeatInterval"> <!-- repeat every 8 hours (14,400,000 milliseconds) --> <value>14400000</value> </property> </bean> <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="startupDelay"> <value>10</value> </property> <property name="triggers"> <list> <ref local="assetSearchTrigger"/> </list> </property> </bean>
I understand why my service isn't there, as I haven't wired it in yet. But why did the String and int not populate? If I make them regular properties of the Job, they work fine.Code:public final class AssetSearch extends QuartzJobBean { static private final Log logger = LogFactory.getLog(AssetSearch.class); private int millisecondsBetweenJobs; private ApplicationContext appContext; private Scheduler scheduler; private String childJobBeanName; private MyService myService; public void setMillisecondsBetweenJobs(int millisecondsBetweenJobs) { this.millisecondsBetweenJobs = millisecondsBetweenJobs; } public void setApplicationContext(ApplicationContext appContext) { this.appContext = appContext; } public void setChildJobBeanName(String childJobBeanName) { this.childJobBeanName = childJobBeanName; } public void setMyService(MyService myService) { this.myService = myService; } protected void setScheduler(Scheduler scheduler) { this.scheduler = scheduler; } /** * @param context information about the job to be scheduled */ protected void executeInternal(JobExecutionContext context) { logger.info("AssetSearch Executing. . . "); setScheduler(context.getScheduler()); logger.debug("AssetSearch internals: " + this.toString()); // Do stuff logger.info("AssetSearch Job Scheduling Complete. "); } }
I also thought I read somewhere (of course I can't find it now), that it would also populate the applicationContext from the SchedulerContext or JobExecutionContext the same way. Which explains why appContext didn't get populated.
Thanks for the assist.


Reply With Quote