問題描述
在springboot項目里配置了xxl-job2.3.0,但是執(zhí)行器無法自動注冊
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
執(zhí)行器無法自動注冊到xxl-job-admin
排查過程
經過debug發(fā)現,是spring沒有加載xxlJobExecutor這個Bean
debug流程(SpringApplication.run()–>SpringApplication.refreshContext()–>SpringApplication.refresh() -->SpringApplication.finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory))
解決方法
自己配置個xxlJobExecutor Bean
文章來源:http://www.zghlxwxcb.cn/news/detail-596270.html
@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,執(zhí)行器也注冊到了xxl-job-admin文章來源地址http://www.zghlxwxcb.cn/news/detail-596270.html
到了這里,關于xxl-job執(zhí)行器無法自動注冊的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!