您的位置:首页 > 其它

SSM框架配置定时任务

2018-02-09 16:20 393 查看
在springmvc.xml配置文件中,添加如下配置:
在bean下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开启定时任务扫描:
<task:annotation-driven/>
<context:component-scan base-package="com.yyg.timer"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<task:scheduler id="myScheduler" pool-size="10"/>Java代码:@Component
public class InsertVideoInfoJob {

@Autowired
private WXVideoReadyDao readyVideoDao;

@Scheduled(cron = "0 5 0 ? * TUE")
public void insertVideoInfo () {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//获取未推送的最早的一条记录
WXVideoReadyModel param = new WXVideoReadyModel();
List<WXVideoReadyModel> list = readyVideoDao.select(param);
System.out.println("已获取到微推送视频");
if(list.size() > 0){
for (WXVideoReadyModel model : list) {
System.out.println("视频信息已插入视频表");
//更新视频预备表---视频已推送
WXVideoReadyModel alreadyPut = model;
alreadyPut.setIsInput(1);
readyVideoDao.update(alreadyPut);
System.out.println("更新视频预备表");
}

}
}
}到此为止就好了。

其实开始的时候我在springmvc.xml文件下 并没有加 
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<task:scheduler id="myScheduler" pool-size="10"/> 所以启动会报错但是定时任务依旧会执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: