xxl-job执行器无法自动注册
xxl-job
xxl-job: 是一个分布式任务调度平台,核心设计目标是开发迅速、学习简单、轻量级、易扩展。
项目地址:https://gitcode.com/gh_mirrors/xx/xxl-job
免费下载资源
·
问题描述
在springboot项目里配置了xxl-job2.3.0,但是执行器无法自动注册
yaml配置如下:
xxl:
job:
admin:
enable: true
address: http://192.xxx.xxx.xxx:38080/xxl-job-admin
password: admin
username: 123456
accessToken:
executor:
appname: test-executor
address:
ip:
port: 9993
logpath: /data/applogs/xxl_job/jobHandler
logretentiondays: 7
执行器无法自动注册到xxl-job-admin
排查过程
经过debug发现,是spring没有加载xxlJobExecutor这个Bean
debug流程(SpringApplication.run()–>SpringApplication.refreshContext()–>SpringApplication.refresh() -->SpringApplication.finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory))
解决方法
自己配置个xxlJobExecutor Bean
@Configuration
@Slf4j
public class XxlJobConfig {
@Value("${xxl.job.admin.address}")
private String adminAddress;
@Value("${xxl.job.executor.address}")
private String address;
@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.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Value("${xxl.job.accessToken}")
private String token;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddress);
xxlJobSpringExecutor.setAppname(appName);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(token);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
配置完成后,再次debug启动服务,可以看到beanFactory里有xxlJobExecutor Bean,执行器也注册到了xxl-job-admin
GitHub 加速计划 / xx / xxl-job
27.15 K
10.79 K
下载
xxl-job: 是一个分布式任务调度平台,核心设计目标是开发迅速、学习简单、轻量级、易扩展。
最近提交(Master分支:3 个月前 )
e5d26ba2 - 3 个月前
977ad87b - 3 个月前
更多推荐
已为社区贡献6条内容
所有评论(0)