xxl-job报错:xxl-job registry fail:The access token is wrong

1、报错信息

.ExecutorRegistryThread    : >>>>>>>>>>> xxl-job registry fail, registryParam:RegistryParam{registryGroup='EXECUTOR', registryKey='xxl-job-executor-sample', registryValue='http://192.168.133.1:9999/'}, registryResult:ReturnT [code=500, msg=The access token is wrong., content=null]

报错场景:

      在使用springboot整合xxl-job中,创建“执行器”向“调度中心注册的时候”提示注册失败,原因是因为token出错。

2、解决办法

在解决这个问题的时候需要注意两点

2.1、注意点1:使用的版本

我使用的是最新版本的xxl-job-2.4.0版本,配置如下,

重点是需要加入xxl.job.accessToken: default_token

server:
  port: 8082

xxl:
  job:
    accessToken: default_token
    admin:
      addresses: http://localhost:8080/xxl-job-admin
    executor:
      appname: xxl-job-executor-sample

如果你使用的是xxl-job-2.2.x版本配置的时候略,在使用路径上略有不同

xxl:
  job:
     admin:
        accessToken

重点:只配置这点是不行的,还要进行依赖注入

2.2、注意点2:配置依赖注入

需要在xxl-job的配置类中通过@Value将applicaiton.yml中xxl.job.accessToken的值获取到并注入到

xxlJobSpringExecutor 中。

@Slf4j
@Configuration
public class xxlJobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${xxl.job.executor.appname}")
    private String appname;

    @Value("${xxl.job.accessToken}")
    private String accessToken;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname);
        xxlJobSpringExecutor.setAccessToken(accessToken);
       /*   xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);*/
        return xxlJobSpringExecutor;
    }
}

3、为什么在2.4.0版本中需要写token这个参数

其实在更早期的版本中,这个参数不是必选项,但是在最新的版本中考虑到安全性的问题,token变成了默认选项,在不修改调度中心的情况下,执行器必须加上token。

下面是调度器源码的token配置:

6974cf7e8be1465b977b92b9623bf261.png

 

所以在使用的时候还需要注意token的名称,调度器和执行器的名称需要匹配。

4、源码下载

https://download.csdn.net/download/tangshiyilang/88663604

 

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雾林小妖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值