springquartz-multipleschedules(cron)用于单个目标方法

nkoocmlb  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(210)

我正在使用springquartz一天运行一个方法多次。一次是6:00,7:15,9:30,15:00,18:40。我发现这些时间表可以容纳在多个cron表达式中。现在我使用bean来创建这些触发器:

<bean id="xyzSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="triggers" ref="triggersList" />
</bean>

<util:list id="triggersList" value-type="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
   <ref bean="trigger1"/>
   <ref bean="trigger2"/>
   <ref bean="trigger3"/>
   ....
</util:list>

<bean id="trigger1" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
   <property name="jobDetail">
      <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDeatilFactoryBean">
         <property name="targetObject" ref="invokingObjectBean"/>
         <property name="targetMethod" value="invokingMethod"/>
      </bean>
   </property>
   <property name="cronExpression" value="cron1" />
</bean>

    <bean id="trigger2" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
   <property name="jobDetail">
      <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDeatilFactoryBean">
         <property name="targetObject" ref="invokingObjectBean"/>
         <property name="targetMethod" value="invokingMethod"/>
      </bean>
   </property>
   <property name="cronExpression" value="cron2" />
</bean>

<---- And similarly trigger 3, 4 and so on ---->

我正在为上面的每个触发器创建多个bean。我在想是否有更好的办法。可能正在使用spel。或者有没有一种方法可以为一个触发器设置多个cron表达式?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题