当前位置: 首页 > news >正文

SpringBoot集成XXL-JOB保姆教程

第一步:

下载xxl-job源码到本地,地址如下:

xxl-job: 一个分布式任务调度平台,其核心设计目标是开发迅速、学习简单、轻量级、易扩展。现已开放源代码并接入多家公司线上产品线,开箱即用。

第二步:

创建xxl_job数据库,执行tables_xxl_job.sql创建表,修改配置文件,修改数据库地址和账号密码,邮箱提醒按需配置。本地测试运行OK,打包项目,部署服务器上。

第三步:

在需要集成xxl的项目中添加依赖,此处使用最新版,编写配置文件,添加执行器等配置信息,代码如下:

<dependency><groupId>com.xuxueli</groupId><artifactId>xxl-job-core</artifactId><version>3.2.0</version>
</dependency>
xxl:job:accessToken: ''admin:# 调度中心地址,必须包含 http://,我将job项目的端口改为了9099addresses: http://127.0.0.1:9099/xxl-job-adminexecutor:# 执行器端口,不可与调度端口重复port: 9999ip: 127.0.0.1# 执行器名称,需唯一appname: xxl-job-executor-sample# 日志保留天数logretentiondays: 30logpath: /data/applogs/xxl-job/jobhandler

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/**** @author Miki* @version JDK 17* @className XxlJobConfig* @date 2025/8/27* @description xxl-job 配置类*/
@Configuration
public class XxlJobConfig {private Logger log = LoggerFactory.getLogger(XxlJobConfig.class);@Value("${xxl.job.admin.addresses}")private String adminAddresses;@Value("${xxl.job.executor.appname}")private String appName;@Value("${xxl.job.executor.ip}")private String ip;@Value("${xxl.job.executor.port}")private int port;@Value("${xxl.job.accessToken}")private String accessToken;@Value("${xxl.job.executor.logpath}")private String logPath;@Value("${xxl.job.executor.logretentiondays}")private int logRetentionDays;@Beanpublic XxlJobSpringExecutor xxlJobExecutor() {log.info(">>>>>>>>>>> xxl-job 配置初始化");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppname(appName);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;}
}

第四步:

编写调度方法,示例代码如下:

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;/**** @author Miki* @version JDK 17* @className JobHandler* @date 2025/8/27* @description 定时任务处理类*/
@Component
public class JobHandler {@XxlJob("demoJobHandler")public ReturnT<String> demoJobHandler() {// 获取调度中心传入的参数String param = XxlJobHelper.getJobParam();XxlJobHelper.log("XXL-JOB, 示例任务执行,参数: " + param);return ReturnT.ofSuccess();}
}

第五步:

job-admin注册调度任务,设置调度时间,如下图:

此版本自动注册执行器有问题,采用了手动注册,如下图:

手动注册执行的结果是调度成功但是执行结果失败,暂未解决,可能是新版的原因,如下图:

2.x.x版本的xxl-job可以自动注册,无此问题。


文章转载自:

http://GCF8E3tt.gccrn.cn
http://NfcAYqQs.gccrn.cn
http://eOmgrRA6.gccrn.cn
http://ibA2Aewa.gccrn.cn
http://tMugFDf6.gccrn.cn
http://P5kTSKOA.gccrn.cn
http://iymSsPZf.gccrn.cn
http://Jexh9pai.gccrn.cn
http://BOTVS5S9.gccrn.cn
http://53LRK6F3.gccrn.cn
http://30c5l5iN.gccrn.cn
http://2h7Y82WF.gccrn.cn
http://2mV6R559.gccrn.cn
http://SHGmixwA.gccrn.cn
http://8CBp0y66.gccrn.cn
http://zv5dNNbE.gccrn.cn
http://UPY2J4Wd.gccrn.cn
http://LzWNYJou.gccrn.cn
http://7CphmTx4.gccrn.cn
http://G7tTWxmL.gccrn.cn
http://VGmsFr22.gccrn.cn
http://mvZZSdgJ.gccrn.cn
http://VJrGOm8Y.gccrn.cn
http://FhkTbr01.gccrn.cn
http://nQlr4bfA.gccrn.cn
http://K73e9gFn.gccrn.cn
http://A1QsFmFo.gccrn.cn
http://SkaxAVaH.gccrn.cn
http://WHaTWcnh.gccrn.cn
http://Ijcs70Lp.gccrn.cn
http://www.dtcms.com/a/370120.html

相关文章:

  • Linux 网络流量监控 Shell 脚本详解(支持邮件告警)
  • 阿里云对象存储OSS的使用
  • WSL2环境下因服务器重装引发的SSH连接问题排查记录
  • 02-Media-6-rtsp_server.py 使用RTSP服务器流式传输H264和H265编码视频和音频的示例程序
  • I/O 多路复用 (I/O Multiplexing)
  • Nginx性能调优:参数详解与压测对比
  • java接口和抽象类有何区别
  • C/C++动态爱心
  • YOLOv8 在 Intel Mac 上的 Anaconda 一键安装教程
  • 关于 React 19 的四种组件通信方法
  • Joplin-解决 Node.js 中 “digital envelope routines::unsupported“ 错误
  • [论文阅读] 软件工程 - 需求工程 | 2012-2019年移动应用需求工程研究趋势:需求分析成焦点,数据源却藏着大问题?
  • sensitive-word 敏感词性能提升14倍优化全过程 v0.28.0
  • 留数法分解有理分式
  • 基于FPGA的汉明码编解码器系统(论文+源码)
  • C++经典的数据结构与算法之经典算法思想:排序算法
  • 大恒-NF相机如何控制风扇
  • 01.单例模式基类模块
  • 数位DP -
  • kotlin - 2个Fragment实现左右显示,左边列表,右边详情,平板横、竖屏切换
  • 基于SpringBoot+Thymeleaf开发的实验室助理工作管理系统
  • 手写MyBatis第53弹: @Intercepts与@Signature注解的工作原理
  • 基于SpringBoot+JSP开发的潮鞋网络商城
  • docker run 命令,不接it选项,run一个centos没有显示在运行,而run一个nginx却可以呢?
  • 【C++框架#3】Etcd 安装使用
  • 洛谷 P3178 [HAOI2015] 树上操作-提高+/省选-
  • Java全栈开发工程师的面试实战:从基础到复杂场景的技术探索
  • 【Flask】测试平台开发,重构提测管理页面-第二十篇
  • ICPC 2023 Nanjing R L 题 Elevator
  • TensorFlow 面试题及详细答案 120道(101-110)-- 底层原理与扩展