ssm框架集成quartz任务调度

1.quartz下载链接网址:http://www.quartz-scheduler.org/

2.点击download

3.这里下载2.2版本

4.下载成功后解压

5.导包

6.新建普通java类

7.新建配置文件

xml配置文件代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
   <!-- 1.托管要执行的任务 -->
   <!-- 要调用的工作类 -->
   <bean id="job1" class="com.song.work.job.job1"></bean>
   <!-- 2.定义任务列表 -->
   <!-- 定义调用对象和调用对象的方法 -->
   <bean id="jobDtetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
	    <!-- 目标执行任务job1-->
	    <!-- 调用的类 -->
	    <property name="targetObject"> <ref bean="job1"/> </property> 
	     <!-- 配置任务执行的方法-->
	     <!-- 调用类中的方法 -->
	    <property name="targetMethod"> <value>work</value> </property>
   </bean>
   <!-- 3.定义触发器 -->
   <bean id="CronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
     	<!-- 3.1.何时触发 使用cronExpression定义执行规则 -->
        <!-- cron表达式 -->
            <property name="cronExpression">
                 <!-- 此处的时间自定义 -->
                <value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value>
            </property>
     	<!-- 3.2.触发啥 -->
     	<property name="jobDetail"> <ref bean="jobDtetail1"/></property>
    </bean>
  	<!-- 4.定义调度器-->
   	<bean id="schedule1" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="CronTrigger1"/>
                </list>
            </property>
     </bean>
   
   </beans>

代码解析:

调度器调动触发器

触发器触发任务列表

任务列表配置任务

报错:

class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class

解决方法:

将CronTriggerBean修改为CronTriggerFactoryBean。

成功!

学习视频:https://v.youku.com/v_show/id_XMTgyNzUzNDkzNg==.html?spm=a2hbt.13141534.app.5~5!2~5!2~5~5~5!2~5~5!2~5!2~5!2~5~5!25~A

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值