Announcement Announcement Module
Collapse
No announcement yet.
Dynamic discovery of Quartz triigers by SchedulerFactoryBean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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

    Comment


    • #3
      That's a good idea! Thanks!

      Comment

      Working...
      X