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

}

结果:一直输出:

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

原文地址:https://www.cnblogs.com/lshan/p/11169009.html