Results 1 to 3 of 3

Thread: QuartzJobBean not being populated

  1. #1
    Join Date
    Aug 2004
    Location
    Atlanta, GA
    Posts
    129

    Default QuartzJobBean not being populated

    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:

    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)".
    Yet, when I execute, nothing is there:

    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 &#40;600,000 milliseconds&#41; -->
                <value>0</value>
            </property>
            <property name="repeatInterval">
                <!-- repeat every 8 hours &#40;14,400,000 milliseconds&#41; -->
                <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>

    Code:
    public final class AssetSearch extends QuartzJobBean
    
    &#123;
        static private final Log logger = LogFactory.getLog&#40;AssetSearch.class&#41;;
    
        private int millisecondsBetweenJobs;
        private ApplicationContext appContext;
        private Scheduler scheduler;
        private String childJobBeanName;
        private MyService myService;
    
        public void setMillisecondsBetweenJobs&#40;int millisecondsBetweenJobs&#41;
        &#123;
            this.millisecondsBetweenJobs = millisecondsBetweenJobs;
        &#125;
    
        public void setApplicationContext&#40;ApplicationContext appContext&#41;
        &#123;
            this.appContext = appContext;
        &#125;
    
        public void setChildJobBeanName&#40;String childJobBeanName&#41;
        &#123;
            this.childJobBeanName = childJobBeanName;
        &#125;
    
        public void setMyService&#40;MyService myService&#41;
        &#123;
            this.myService = myService;
        &#125;
    
        protected void setScheduler&#40;Scheduler scheduler&#41;
        &#123;
            this.scheduler = scheduler;
        &#125;
    
        /**
         * @param context information about the job to be scheduled
         */
        protected void executeInternal&#40;JobExecutionContext context&#41;
        &#123;
    
            logger.info&#40;"AssetSearch Executing. . . "&#41;;
            setScheduler&#40;context.getScheduler&#40;&#41;&#41;;
            
            logger.debug&#40;"AssetSearch internals&#58; " + this.toString&#40;&#41;&#41;;
            // Do stuff
            logger.info&#40;"AssetSearch Job Scheduling Complete. "&#41;;
        &#125;
    &#125;
    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.

    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.
    Randy

  2. #2
    Join Date
    Aug 2004
    Location
    Atlanta, GA
    Posts
    129

    Default

    OK, apparently you need to define the applicationContextSchedulerContextKey for the SchedulerFactory in order for it to find the pre-configured properties in the job map. :oops:

    I think it might be good to default this value.
    Randy

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    This value is not always applicable, so a default is not appropriate...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. iBatis 2.0 SqlMapClientTemplate not populated
    By parkerlouis in forum Data
    Replies: 8
    Last Post: Dec 3rd, 2008, 08:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •