SSM项目设置定时任务

最近在做学年设计,发现这个模块功能挺有意思的,记录下
第一步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表达式

http://cron.qqe2.com/

注:Test定时任务类必须放在配置的包扫描下

直接在SSM项目中配置就可以,启动服务就能运行。

文章来源于csdn,如有侵权,请联系删除。

https://blog.youkuaiyun.com/xi_haibin/article/details/82834487

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值