# xxl-job-task-spring-boot-starter
**Repository Path**: feiyuthomas/xxl-job-task-spring-boot-starter
## Basic Information
- **Project Name**: xxl-job-task-spring-boot-starter
- **Description**: 开箱即用的xxl-job任务动态管理
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 11
- **Created**: 2024-08-09
- **Last Updated**: 2024-08-16
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
开箱即用的xxl-job任务后台动态管理
# 功能
- xxl-job模拟登录
- xxl-job执行器:动态新增、动态注册、动态查询
- xxl-job执行任务:动态添加、动态更新、动态启动、动态停止
# 特性
- xxl-job-admin的API需要登录才能访问,本项目中进行了模拟登录,获取到cookie,然后携带cookie访问API
- 对接口访问进行统一封装,扩展性强
- 将工程封装成spring-boot-starter,开箱即用
- 本项目对接的xxl-job接口,都进行了单元测试,单元测试案例见`com.chuanxi.wow.xxl.job.task#XxlJobTest`
# 如何使用
1、下载源码
2、打成jar,放入maven仓库
3、引用
```xml
com.mading
xxl-job-task-spring-boot-starter
1.0-SNAPSHOT
```
4、配置xxl-job
```properties
# 前缀可自行在XxlJobProperties中修改
xxl.adminAddresses=http://127.0.0.1:8080/xxl-job-admin
xxl.appname=${spring.application.name}
xxl.logretentiondays=30
xxl.port=9999
xxl.accessToken=289d5e0b-e83b-40a1-87ec-fd7b2335f15c
```
5、使用
```java
package com.mdw.xxl.job.task;
@Slf4j
@SpringBootTest(classes = XxlJobAutoConfiguration.class)
@RunWith(SpringRunner.class)
public class XxlJobTest {
@Autowired
private XxlJobProperties xxlJobProperties;
@Autowired
private XxlJobClient xxlJobClient;
// 执行器id
private static final Integer jobGroup = 3;
// 执行任务id
private static final Integer jobId = 10;
@Test
public void testAddJob() {
String executorHandler = "checkAccountTask";
String author = "马丁丁";
JobAddRequest request = new JobAddRequest();
request.setJobGroup(jobGroup)
.setJobDesc("商户-微信对账")
.setJobCron("0 0 7 * * ?")
.setExecutorHandler(executorHandler)
.setExecutorParam("paycenter-wx")
.setAuthor(author);
String result = xxlJobClient.execute(request);
log.info(result);
JobAddRequest request2 = new JobAddRequest();
request2.setJobGroup(jobGroup)
.setJobDesc("商户-支付宝对账")
.setJobCron("0 0 4 * * ?")
.setExecutorHandler(executorHandler)
.setExecutorParam("paycenter-zfb")
.setAuthor(author);
String result2 = xxlJobClient.execute(request);
log.info(result2);
}
}
```
# 参考
xxl-job动态添加执行任务:`https://blog.csdn.net/niugang0920/article/details/117601547`