依賴:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-quartz --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId> <version>2.1.0.RELEASE</version> </dependency>
定時任務: 項目中無其他任何其他配置
定時方法:
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component @EnableScheduling public class QuertzTest { @Scheduled(cron = "0/2 * * * * ?") public void testimer() { System.err.println("#########"); System.err.println("#########"); System.err.println("#########"); System.err.println("#########"); System.err.println("#########"); } }
結果:一直輸出:
#########
#########
#########
#########
#########