SpringBoot功能持续更新

时间:2023-03-09 22:17:10
SpringBoot功能持续更新

【定时任务】

1.启动总开关

@EnableScheduling加在@SpringBootApplication注解的start入口处,表示启动总开关

@SpringBootApplication
@EnableScheduling
public class start {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(start.class, args);
    }
}

2.再单独给方法加配置

@Scheduled(cron="0/5 * * * * ?")每5秒打印当前时间

    @Scheduled(cron="0/5 * * * * ?")
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
    }

SpringBoot功能持续更新

备注:cron表达式,秒分时天等等,具体用到可以再百度