配置
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
源码
package com.comtop.mop.app.service.sync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Author: 作者
* @Date: 2018/12/17 09:33
* @Description:
*/
@Component
public class testDemo {
@Scheduled(cron = "0/5 * * * * ?")
public void test(){
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(new Date())+" *********** ");
}
}
打印结果
2018-12-17 09:43:05 ***********
2018-12-17 09:43:10 ***********
2018-12-17 09:43:15 ***********
2018-12-17 09:43:20 ***********
2018-12-17 09:43:25 ***********
2018-12-17 09:43:30 ***********
2018-12-17 09:43:35 ***********
2018-12-17 09:43:40 ***********
2018-12-17 09:43:45 ***********
2018-12-17 09:43:50 ***********
2018-12-17 09:43:55 ***********
定时时间参考:https://blog.csdn.net/jack_bob/article/details/78786740