定时任务

springboot启动类:

@EnableScheduling //开启定时任务功能注解
@SpringBootApplication
public class Springboot05TestApplication {

    public static void main(String[] args) {
        SpringApplication.run(Springboot05TestApplication.class, args);
    }

}

service:

@Service
public class ScheduledService {
    //在一个特定的时间执行这个方法
    //cron表达式-  秒 分 时 日 月 周几
    @Scheduled(cron = "0 * * * * 0-7")
    public void hell(){
        System.out.println("hello-你被执行了");
    }
}

 

posted @ 2020-06-29 10:24  Dorom  阅读(79)  评论(0)    收藏  举报