SpringBoot中使用分布式任务调度平台XxL-Job

本文档详细介绍了如何配置和使用XXL-JOB来创建和执行定时任务。首先,通过引入相关依赖并排除Groovy库,然后创建一个任务类,继承自XxlJobHandler,并实现必要的方法。在任务类上添加@Component和@JobHandler注解,使得Spring容器能在指定的cron表达式时间执行任务。这样,就能实现基于XXL-JOB平台的定时任务推送功能。
摘要由CSDN通过智能技术生成
1. 搭建步骤请参考xxl-job官方文档

xxl官方文档

2. 具体使用
  1. 引入依赖

    <properties>
        <xxl-job-core.version>1.9.1</xxl-job-core.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>com.xuxueli</groupId>
            <artifactId>xxl-job-core</artifactId>
            <version>${xxl-job-core.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>groovy-all</artifactId>
                    <groupId>org.codehaus.groovy</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    
  2. 创建任务类 继承XxlJobHandler ,实现 doExecuteOnCompanyId()和parseParam()方法

    @Component(value = "pushEnterpriseJob")
    @JobHandler(value = "pushEnterpriseJob")
    public class PushEnterpriseJob extends XxlJobHandler<JsonObject> {
    
        @Override
        protected void doExecuteOnCompanyId(Long aLong, JsonObject jsonObject, int i, int i1) throws Exception {
            // 编写业务逻辑
               }
            }
        }
    
        @Override
        protected JsonObject parseParam(String s) {
            return null;
        }
    }
    
  3. 只需要在任务类上加上@Component和@JobHandler注解,spring容器在执行时,就会扫到该任务类,根据你在xxl-job平台的cron表达式设置的时间进行推送
    在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值