Results 1 to 3 of 3

Thread: Dynamic discovery of Quartz triigers by SchedulerFactoryBean?

  1. #1

    Default Dynamic discovery of Quartz triigers by SchedulerFactoryBean?

    Hi all,

    I have a scenario where I have a SchedulerFactoryBean and scattered CronTriggerBean bean definitions across multiple JARs. Is there a way to dynamically discover the triggers in the context and register them? SchedulerFactoryBean takes an array (or list) of Triggers as follows:

    Code:
    <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="triggers">
    			<list>
    				<ref bean="triggerBean1" />
    				<ref bean="triggerBean2" />
    			</list>
    		</property>
    </bean>
    I would like to discover all CronTriggerBean beans defined in the Spring context and add them to the schedulerFactoryBean? I was thinking of doing it with a BeanPostProcessor but there is no addTrigger() method in schedulerFactoryBean.

    Thanks a lot!
    Nazaret Kazarian

  2. #2
    Join Date
    Mar 2012
    Posts
    6

    Default

    Hi,

    Here is a way to do this. You can override SchedulerFactoryBean and make it BeanFactoryAware. Find all of the Triggers by type off of the BeanFactory and then before you delegate to the parent SchedulerFactoryBean#afterPropertiesSet(), call setTriggers() with all of the triggers you've discovered.

    Here is a fully-executable example on GitHub:

    https://github.com/jmolly/answers/bl...ctoryBean.java

    --AD
    http://www.jmolly.com

  3. #3

    Default

    That's a good idea! Thanks!
    Nazaret Kazarian

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
  •