Announcement Announcement Module
Collapse
No announcement yet.
MethodInvokingJobDetailFactoryBean not fetching new target instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MethodInvokingJobDetailFactoryBean not fetching new target instance

    Hello,

    I am using org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean in my application context as part of a quartz scheduling process. I need this class to get a new instance of the target class every time it triggers. I have defined all of my beans as prototype for concurrency purposes but the factory bean keeps using the same instance of the target. How can I configure to use a new instance?

    HTML Code:
    in applicationContext.xml:
    
            <bean id="launch" class="net.tds.daemon.service.LaunchControlsAuditDriver" scope="prototype"/>
    
    in schedulerContext.xml:
    
            <import resource="classpath:applicationContext.xml"/>
    
            <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      		<property name="targetObject" ref="launch" />
      		<property name="targetMethod" value="run" />
      		<property name="concurrent" value="true" />
    	</bean>
    	
    	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        	     <property name="jobDetail" ref="jobDetail" />
        	     <property name="cronExpression" value="${cron.expression}" />
    	</bean>
    	
    	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="configLocation" value="classpath:quartz.properties"/>
    		<property name="autoStartup" value="${auto.startup}"/>
        	        <property name="triggers">
            	     <list>
                	        <ref bean="cronTrigger" />
            	    </list>
        	        </property>
    	</bean>

  • #2
    Instead of declaring jobDetail as in your config. do the following


    <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvok ingJobDetailFactoryBean"> <property name="targetBeanName" value="launch" /> <property name="targetMethod" value="run" /> <property name="concurrent" value="true" /> </bean>
    This would result in the factory bean implementation looking up spring container for that bean name and hence your prototype strategy would work. For details look at the javadoc of MethodInvokingJobDetailFactoryBean.
    Last edited by objectamit; Dec 13th, 2012, 11:54 PM.

    Comment


    • #3
      Thank you for your response. I'll try this out.

      Comment

      Working...
      X