springboot quartz 注解的最簡單使用


依賴:

<!-- 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("#########");
    }
    

}

結果:一直輸出:

#########
#########
#########
#########
#########

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM