—— 阿尔伯特·爱因斯坦

程序员の奇妙冒险

Spring BootSpring Boot
2025-05-11 18:22阅读:135评论:0

xxl-job 告别手动配置任务

项目地址:https://github.com/osinn/xxl-job-auto-register 引入依赖 在Spring boot项目中引入依赖 application.yml配置 添加注册注解 通过@XxlRegister注解启动项目时会自动注册到xxl-job中,参数修改后重启项目也会更

  • 项目地址:https://github.com/osinn/xxl-job-auto-register
_PROTECTED0__
  • 在Spring boot项目中引入依赖
1
2
3
4
5
6
7
8
9
10
11
12
<dependency>
<groupId>io.github.osinn</groupId>
<artifactId>xxl-job-auto-register</artifactId>
<version>0.0.2</version>
</dependency>
 
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
 
_PROTECTED0__
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
xxl:
job:
# 启用xxl-job配置,否则需要自行配置注入XxlJobSpringExecutor
enable: true
# 是否启用分布式锁住自动配置,避免多台服务器并发自动注册,依赖 redisson
enabled-distributed-lock: true
accessToken: default_token
admin:
addresses: http://127.0.0.1:8080/xxl-job-admin
password: 123456
username: admin
executor:
address: ''
address-list: http://127.0.0.1:9999
addressType: 1
app-name: xxl-job-executor-test
ip: 127.0.0.1
log-path: /data/applogs/xxl-job/jobhandler
log-retention-days: 30
port: 9999
title: Exe-Titl
 
_PROTECTED0__
1
2
3
4
5
6
7
8
9
10
11
12
@Service
public class TestService {
 
@XxlJob(value = "testJob")
@XxlRegister(cron = "0 0 0 * * ? *",
author = "wencai_cai",
jobDesc = "测试job")
public void testJob(){
System.out.println("自动注册");
}
}
 
  • 通过___PROTECTED_1__0__注解启动项目时会自动注册到xxl-job中,参数修改后重启项目也会更新到xxl-job中,从而告别了手动配置任务
评论(0)
暂无评论来抢沙发吧~