首页 > 编程语言 > 详细

springboot与SSM的定时任务

时间:2020-03-23 13:12:57      阅读:50      评论:0      收藏:0      [点我收藏+]

SSM:

在@service中写以下方法,具体时间参数的设定,可以参照以下文章

https://www.cnblogs.com/2016-10-10/p/6283321.html

@Scheduled(cron = "0/5 * * * * ?")
    public void testwork() {
        Calendar date=Calendar.getInstance();
        System.err.println(date.getTime()+"毫秒为:  "+System.currentTimeMillis());
        MyBlog.setOld_day(date.get(Calendar.DAY_OF_MONTH));
        MyBlog.setOld_month(date.get(Calendar.MONTH)+1);
        MyBlog.setYou_day(date.get(Calendar.DAY_OF_MONTH));
        MyBlog.setYou_month(date.get(Calendar.MONTH)+1);
        System.out.println(MyBlog.getOld_day());
        System.out.println(MyBlog.getOld_month());
        System.out.println(MyBlog.getYou_day());
        System.out.println(MyBlog.getYou_month());
        }



并且需要在application.xml中配置以下属性

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"

同时开启定时任务即可

<task:annotation-driven/>

 

SpringBoot

首先需要在主类上加上定时任务注解

@EnableScheduling   // 开启定时任务

之后在@Service类中写定时方法即可

    /*
* second minute, hour, day of month, month,week
* and day of week. e.g. {@code "0 * * * * MON-FRI"} means once per minute on
* */
// @Scheduled(cron="0 * * * * MON-FRI")
// public void schedul(){
// // 这个方法就可以实现每天定时检查数据,若发现不对的地方即可调用方法通知管理员。
// System.out.println("这是一个定时方法~");
//
// }

springboot与SSM的定时任务

原文:https://www.cnblogs.com/dddchongya/p/12551315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!