springboot native timing task

1. Add the @EnableScheduling annotation to the main class
@EnableScheduling
@EnableFeignClients
@EnableDiscoveryClient
@ComponentScan("com.atguigu")
@SpringBootApplication
@MapperScan("com.atguigu.staservice.mapper")
public class StaApplication {
    public static void main(String[] args) {
        SpringApplication.run(StaApplication.class, args);
    }
}
2. Set the timing task execution time and specific tasks
package com.atguigu.staservice.schedule;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduleTask {
    @Scheduled(cron="0/5 * * * * ?")
    public void test(){
        System.out.println("方法一执行了");
    }
}

Guess you like

Origin blog.csdn.net/sharesb/article/details/131450759