Announcement Announcement Module
No announcement yet.
how to dynamically pass parameters of method Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to dynamically pass parameters of method

    I am using Spring quartz to implement some schedule tasks. My initial configuration works fine, it looks like:
        <bean id="quartzJobDetailSample" class="..." />
        <bean id="jobDetailId" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="quartzJobDetailSample" />
            <property name="targetMethod" value="methodName"/>
            <property name="arguments">
        <bean id="jobTriggerId" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="jobDetailId" />
            <property name="cronExpression" value="0/15 * * * * ?" />
        <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                    <ref bean="jobTriggerId" />
    But I need to manage all tasks through UI startup of web application, I wonder if there is some way to pass new parameters to the method. I tried:

    MethodInvokingJobDetailFactoryBean bean = (MethodInvokingJobDetailFactoryBean)getApplication Context().getBean("jobDetailId");
    bean.setArguments(new String[]{"1","2"});
    It turns out the MethodInvokingJobDetailFactoryBean generated a JobDetail instance for the bean with id "jobDetailId", but there's no way to pass arguments to method in JobDetail instance. I know I probably can use DataMap to achieve this, but I don't want to disturb my service layer (here is quartzJobDetailSample class) with any Quartz code if possible.

    If anyone has any idea, please share it. Thanks in advance

  • #2
    It turns out the MethodInvokingJobDetailFactoryBean generated a JobDetail instance for the bean with id "jobDetailId"
    Because that is what a FactoryBean should do. If you really want to access your FactoryBean use a special bean name. You have to use the '&[beanname]' as the name/id of the bean to retrieve. So in your case '&jobDetailId'.


    • #3
      Marten, thanks a lot! I managed to pass new arguments to my scheduled business method with your helpful information.

      MethodInvokingJobDetailFactoryBean bean = (MethodInvokingJobDetailFactoryBean)this.getApplic ationContext().getBean("&jobDetailId");
      bean.setArguments(new String[]{"new argument 1","new argument 2"});
      scheduler.addJob((JobDetail)bean.getObject(), true);
      I initially doubt if it works. Because the isSingleton method of "bean" return true, which indicates getObject() returns the same instance all the time. I just had a try in my test, when I saw the new arguments appearing on console, I was released