- Spring Boot 版本:2.6.1
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
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");
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)