一:在程序入口类中添加注解@EnableScheduling

@SpringBootApplication
@EnableScheduling
public class DemoApplication {

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

二:在一个没有带参数的方法上使用注解Scheduled


@Service
public class ScheduledTest {
    
    @Scheduled(cron = "*/3 * * * * ?")
    public void demoSchedule() {
        System.out.println("执行");
    }
}

三:启动应用则会自动按照cron的规则定时执行任务

相关文章:

  • 2022-01-14
  • 2021-11-29
  • 2021-10-20
  • 2021-11-21
  • 2021-07-19
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-01-11
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案