1.Quartz概述

          Quartz是一个完全由java编写的开源任务调度的框架,通过触发器设置作业定时运行规则,控制作业的运行时间。其中quartz集群通过故障切换和负载平衡的功能,能给调度器带来高可用性和伸缩性。主要用来执行定时任务,如:定时发送信息、定时生成报表等等。

2.使用Quartz

       2.1引入相关依赖

 <!--引入quartz依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>

   2.2 创建创建Quartfig.java

@Component //交于spring容器该类对象
public class QuarzConfig {
    @Autowired
    private StudentMapper studentMapper;
    @Scheduled(cron="0/5 * * * * ? ")
    public void test(){

        System.out.println("----------------------");
    }
}

开启定时器注解

@SpringBootApplication
@MapperScan(basePackages = "com.xal.mapper")
@EnableScheduling //开启定时器注解
@EnableSwagger2
public class SwaggerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SwaggerApplication.class, args);
    }

}

然后运行  查看控制台

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐