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,定时任务时间到了后台自动执行调度。
小总结,有错请指出,谢谢。
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,定时任务时间到了后台自动执行调度。
小总结,有错请指出,谢谢。
相关文章推荐
- Spring之——quartz使用@Scheduled注解执行定时任务
- Spring 3整合Quartz 2实现定时任务一:常规整合 (基于maven构建)
- spring 使用@scheduled注解执行定时任务
- maven项目整合Spring与quartz出现的定时器任务二次重复执行问题(2017年12月2日16:57:32)
- Spring中使用注解 @Scheduled执行定时任务
- java 定时器,固定某个时间执行(Spring+Quartz实现定时任务的配置方法)
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
- springboot动态配置定时任务2种方式,整合Quartz多线程并发执行多个定时任务配置
- spring 第13天 使用@scheduled注解执行定时任务
- spring注解 @Scheduled(cron = "0 0 1 * * *")的使用来实现定时的执行任务
- Spring 3整合Quartz 2实现定时任务一:常规整合 (基于maven构建)
- 使用spring的@Scheduled注解执行定时任务,启动项目不输出警告
- Spring整理系列(08)——spring与quartz整合执行定时任务
- SSH:解决Spring整合quartz定时任务执行两次问题
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
- spring 基于注解的@Scheduled和quartz定时器两种实现
- springboot动态配置定时任务2种方式,整合Quartz多线程并发执行多个定时任务配置
- spring注解 @Scheduled(cron = "0 0 1 * * *")的使用来实现定时的执行任务
- Spring整合Quartz定时任务执行2次,Spring定时任务执行2次
- Spring中使用注解 @Scheduled执行定时任务