一、spring注解方式

 

<!--&lt;!&ndash;配置文件添加允许Spring注解&ndash;&gt;-->
<!--<task:annotation-driven scheduler="qbScheduler"/>-->
<!--<task:scheduler />-->

<!--类-->

import org.springframework.scheduling.annotation.Scheduled

class XXX{

@Scheduled(cron="0 */2 * * * ?") //这里是两分钟触发一次

 public void METHOD(){

//方法要做的事

}

}

二、XML方式

<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="quartzProperties">
<props><!--用于存储内存中的调度信息-->
<prop key="org.quartz.jobStore.class">
org.quartz.simpl.RAMJobStore
</prop>
</props>
</property><!--触发器创建-->
<property name="triggers">
<list>
<ref bean="XXXTrigger"/>
</list>
</property>
</bean>


<!-- 方法名称去执行任务的一个工厂bean -->
<bean /><!--多个job不会并发运行,默认是true-->
</bean>

<!-调用对应触发器->
<bean />//每两分钟执行一次
</bean>

<!--定义调用目标类-->

<bean />
</beans>

 

相关文章:

  • 2022-02-02
  • 2021-07-09
  • 2022-01-06
  • 2022-01-19
  • 2021-10-11
猜你喜欢
  • 2021-11-29
  • 2021-12-27
  • 2022-02-22
  • 2022-12-23
  • 2021-07-28
  • 2021-04-30
相关资源
相似解决方案