1.首先要用springBoot的定时类要在springBoot的启动类上添加 @EnableScheduling注解
**
*
* @Author: ruanyanghui
* @Company: bibll
* @Email: yanghui.ruan@bibll.com
* @Description: springboot 启动类
* @Date: 2018/8/31 20:08
*/
@SpringBootApplication
@EnableSwagger2
@EnableScheduling
public class WebApp implements WebMvcConfigurer {
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone(Constant.TIMESTAMP_FORMAT_TIMEZONE));
}
public static void main(String[] args) throws IOException {
SpringApplication.run(WebApp.class, args);
}
}
其次在定时任务上注解 如 @Scheduled(cron = "0 0/5 * * * ?") 表示每五分钟执行一次
/**
*
* @Author: ruanyanghui
* @Company: bill
* @Email: yanghui.ruan@bibll.com
* @Description: springboo