版本说明
- Spring Boot 版本:2.6.1
添加web依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
在启动类上添加注解开启任务支持
@SpringBootApplication
@EnableScheduling
public class BootTestApplication {
public static void main(String[] args) {
SpringApplication.run(BootTestApplication.class, args);
}
}
执行任务
@Component
public class TestJob {
@Scheduled(cron = "0 0/1 * * * ?")
public void testJob() {
System.out.println("perform task");
}
}