spring boot(学习笔记第十八课)
- Spring boot的定时任务和Quartz
学习内容:
- Spring boot的定时任务
- Spring boot的Quartz
1. Spring boot的定时任务
- 定义定时任务
- 加入必要的依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
- 在主类里面让
scheduling
生效@SpringBootApplication @EnableScheduling public class DemoApplication {
- 定义
component
,测试scheduling task
@Component public class ScheduledJob { @Scheduled(fixedDelay = 1000) public void fixedDelay() { System.out.println("fixedDelay(1000ms):" + new Date()); } @Scheduled(fixedRate = 2000) public void fixRate() { System.out.println("fixedRate(2000):" + new Date()); } @Scheduled(initialDelay = 1000, fixedRate =<
- 加入必要的依赖