Spring内置Quartz的使用

本文档主要对Spring内置的Quartz如何使用进行一个简单的介绍,在阅读文档之前,请首先确认你的项目里面是否引入了Spring框架

1.首先我们写好需要被调用的方法,做为示例,所以我做了两个方法,一个方法每隔五秒被调用一次,另一个方法每小时的45分00秒被调用一次,两个方法都是在控制台上打印一句话,以表示方法已经被调用,在实际运用过程中,你需要根据实际需求来写你的方法。(在这里,方法名需要与配置文件中的targetMethod一致)

public class QuartzDemo {
    public void lunxun(){
       System.out.println("这是轮询任务(每5秒调用一次)————————————————————");
    }
    public void dingshi(){
        System.out.println("这是定时任务(每小时的45分调用一次)————————————————————");
    }
}

2.现在你需要写一个配置文件,并在applicationContext中引入它(只要能保证这个配置文件在项目启动时能够被Spring所加载就够了,在哪里引入并不重要),我在项目里新建了一个spring-config-quartz.xml做为quartz的配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
	
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值