spring boot 集成 quartz

it2022-05-05  101

分四步

1:导入pom

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId> <version>2.1.6.RELEASE</version> </dependency>

2:创建java

import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class QuartzDemo{ @Scheduled(fixedRate = 5000) public void test(){ System.out.println("每隔5秒执行一次"); } @Scheduled(cron = "0 0/5 * * * ?") public void test1(){ System.out.println("每隔5分钟又执行一次"); } }

3:启动类配置

@EnableScheduling

4:启动服务


最新回复(0)