您的位置:首页 > 编程语言 > Java开发

spring整合Quartz定时器(二)---基于@Scheduled注解执行定时任务

2018-03-07 22:03 211 查看
配置quartz 在spring中需要三个jar包:quartz-1.6.5.jar

commons-collections-3.2.jar

commons-logging-1.1.jar1.实现类@Service
public class testSchdule {

@Scheduled(cron="0/5 * * * * ? ")
public static void syso(){
System.out.println("这是定时器!");
}
}
2.首先spring的配置文件application.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:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"> //扫描
<context:component-scan base-package="com.yyy.test" />
<!-- 注解定时任务 -->
<task:annotation-driven/>
</bean>
注:
xmlns 多加下面的内容:xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schemaLocation多加下面的内容:http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd spring加载application.xml是注册job,定时任务时间到了后台自动执行调度。
小总结,有错请指出,谢谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐