Announcement Announcement Module
No announcement yet.
Dynamic discovery of Quartz triigers by SchedulerFactoryBean? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="triggers">
    				<ref bean="triggerBean1" />
    				<ref bean="triggerBean2" />
    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

    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:



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