Announcement Announcement Module
No announcement yet.
Quartz - setting a jobDataAsMap property to a jobDetailBean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz - setting a jobDataAsMap property to a jobDetailBean

    Hi, I just put together a simple job using the quartz scheduler. The bean config XML file is as follows -

    <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="quartzProperties">
    <prop key="org.quartz.scheduler.instanceName">GTPersiste ntScheduler</prop>
    <prop key="org.quartz.scheduler.instanceId">GTS_STANDALO NE</prop>
    <prop key="org.quartz.scheduler.rmi.export">false</prop>
    <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
    <prop key="org.quartz.scheduler.userTransactionURL">java x.transaction.UserTransaction</prop>
    <prop key="org.quartz.threadPool.class">org.quartz.simpl .SimpleThreadPool</prop>
    <prop key="org.quartz.threadPool.threadCount">3</prop>
    <prop key="org.quartz.threadPool.threadPriority">4</prop>
    <prop key="org.quartz.jobStore.class">org.quartz.impl.jd bcjobstore.JobStoreTX</prop>
    <prop key="org.quartz.jobStore.driverDelegateClass">org. quartz.impl.jdbcjobstore.WebLogicDelegate</prop>
    <prop key="org.quartz.jobStore.dataSource">WeblogicDS</prop>
    <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
    <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
    <prop key="org.quartz.dataSource.WeblogicDS.jndiURL">jdb c/GeoTradesTxDS</prop>
    <prop key="org.quartz.dataSource.WeblogicDS.jndiAlwaysLo okup">false</prop>
    <prop key=" factory.initial">weblogic.jndi.WLInitialContextFac tory</prop>
    <prop key=" provider.url">t3://erezdev:7007</prop>
    <prop key="org.quartz.plugin.shutdownHook.class">org.qua</prop>
    <prop key="org.quartz.plugin.shutdownHook.cleanShutdown" >true</prop>
    <property name="triggers">
    <ref bean="cronMaintenanceTrigger"/>

    <bean id="maintenanceJob" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass">
    <value> nupJob</value>
    <property name="jobDataAsMap">
    <entry key="condition">
    <entry key="jdbcTemplate">
    <ref bean="jdbcTemplate"/>

    <bean id="cronMaintenanceTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
    <property name="jobDetail">
    <ref bean="maintenanceJob"/>
    <property name="cronExpression">
    <value>0/20 * * * * ?</value>

    I have two setters for each property in the scheduled job class - DailyExecutionCleanupJob. The problem is that only the 'condition' property is being set and the 'jdbcTemplate' turns out to be null.
    The 'jdbcTemplate' is being used as a dataSource for initialization for a few other classes and it works fine. I suspect this has to do with the way the properties are set for a scheduled Job i.e. using the JobDataAsMap property and specifying the 'jdbcTemplate' as an entry property.
    Can anyone help shed some light on this? Thanks.

  • #2
    Found the solution

    I needed to register the 'jdbcTemplate' in the scheduler context before i could use it in the job.
    So the only extra spec i had to add to the schedulerFactory was -

    <property name="schedulerContextAsMap">
    <entry key="jdbcTemplate">
    <ref bean="jdbcTemplate"/>