基于注解使用定时框架Quartz

来源:互联网 发布:vb win7 64位 编辑:程序博客网 时间:2024/05/29 08:13

最近复习一下Spring集成Quartz.跑了一个demo特此记录

package task;import org.springframework.context.annotation.Lazy;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;/** * Create by szw on 2017/11/23 10:05 */@Component@Lazy(false)public class SpringTask {    @Scheduled(cron="0/1 * *  * * ? ")    public void task() {        System.out.println("我执行了");    }}

需要在spring的配置文件开启任务注解(别忘了要配置spring扫描相关包)

<?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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">    <!--<context:component-scan base-package="controller"/>-->    <context:component-scan base-package="task"/>    <task:annotation-driven/></beans>


阅读全文
0 0
原创粉丝点击