Results 1 to 3 of 3

Thread: MethodInvokingJobDetailFactoryBean not fetching new target instance

  1. #1

    Default 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. #2
    Join Date
    Dec 2009
    Location
    India
    Posts
    108

    Smile

    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 at 11:54 PM.

  3. #3

    Default

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

Tags for this Thread

Posting Permissions

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