#4006·xxl-job

[Bug] XXL-JOB 3.3.2/3.4.2 无法扫描 @RefreshScope 代理 Bean 中的 @XxlJob Handler

Author: loren-codingCreated Aug 28, 2026Updated Aug 28, 2026

问题描述

任务 Bean 同时使用 @RefreshScope@XxlJob 时,Handler 无法注册。

执行器可以正常启动,但启动日志中没有对应的 Handler 注册记录。触发任务时报错:

job handler [refreshScopeJob] not found

移除 @RefreshScope 后恢复正常。

影响版本

  • 旧版本正常
  • 3.3.2:异常
  • 3.4.2:异常

该问题可能与 3.3.0 开始调整的任务 Bean 扫描逻辑有关。

最小复现

java
  import com.xxl.job.core.context.XxlJobHelper;
  import com.xxl.job.core.handler.annotation.XxlJob;
  import org.springframework.cloud.context.config.annotation.RefreshScope;
  import org.springframework.stereotype.Component;

  @Component
  @RefreshScope
  public class RefreshScopeJob {

      @XxlJob("refreshScopeJob")
      public void execute() {
          XxlJobHelper.log("refreshScopeJob executed");
      }
  }

调度中心配置:

运行模式:BEAN JobHandler:refreshScopeJob

执行结果:

job handler [refreshScopeJob] not found

删除 @RefreshScope 并重启执行器后,Handler 可以正常注册。

原因分析

@RefreshScope 会把任务 Bean 包装为 scoped proxy,并生成:

refreshScopeJob scopedTarget.refreshScopeJob

当前扫描逻辑可能跳过公开代理 Bean,同时又因为只扫描单例 Bean而没有扫描 scopedTarget.* 目标 Bean,最终导致 @XxlJob 未注册。

期望结果

扫描 scoped proxy 时:

  1. 使用目标 Bean 类型查找 @XxlJob 方法;
  2. 注册时仍使用公开代理 Bean,保留刷新能力;
  3. 不提前初始化普通懒加载 Bean;
  4. 不回退现有 Bean 扫描逻辑。

环境信息

  • XXL-JOB:3.4.2
  • JDK:17