最近在做学年设计,发现这个模块功能挺有意思的,记录下
第一步sprinmvc.xml中添加一下内容:
在xmlns下添加:
xmlns:task="http://www.springframework.org/schema/task"
在xsi中添加
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
添加后效果图如下:
第二步:添加设置定时任务代码
需添加到springmvc.xml文件中间位置
<!-- 设置定时任务 -->
<task:annotation-driven/>
第三步:新建定时任务类
package com.etc.time;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by Administrator on 2017/12/20.
*/
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
/**
* @author 席海斌.信息部
* @date 2018年9月25日09:28:51
*/
@Controller
public class taskTest {
/**
* 每天7,8点每隔5分钟刷新一次
*/
@Scheduled(cron = "0/20 * * * * ?")//隔20秒隔行一次
public void fangfaming(){
System.out.println("定时任务一已执行!");
}
}
cron表达式
注:Test定时任务类必须放在配置的包扫描下
直接在SSM项目中配置就可以,启动服务就能运行。
文章来源于csdn,如有侵权,请联系删除。
https://blog.youkuaiyun.com/xi_haibin/article/details/82834487