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