跳到内容
SCRM DOC
后端XXL-JOB定时任务配置创建于2026-03-22更新于 2026-03-22

XXL-JOB 配置

概述

XXL-JOB 是一个分布式任务调度平台,Widiazine SCRM 通过 widiazine-xxljob 模块提供自动配置。


启用 XXL-JOB

1. 添加依赖

<dependency>
    <groupId>org.widiazine.boot</groupId>
    <artifactId>widiazine-xxljob</artifactId>
    <version>${widiazine.version}</version>
</dependency>

2. 添加注解

在启动类上添加 @EnableXxlJob 注解:

@SpringBootApplication
@EnableXxlJob
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

配置文件

application.yml

widiazine:
  xxljob:
    enabled: true
    adminAddresses: http://192.168.1.100:8080/xxl-job-admin
    appname: widiazine-cloud-system
    accessToken: default_token
    logPath: /data/applogs/xxl-job/jobhandler
    logRetentionDays: 30

配置属性说明

属性必填默认值说明
enabled否true是否启用 XXL-JOB
adminAddresses是-调度中心地址
appname是-执行器名称
accessToken否-通讯令牌
logPath是-日志路径
logRetentionDays否30日志保留天数

自动配置原理

XxlJobConfiguration

@Configuration
@EnableConfigurationProperties({XxlJobProperties.class})
@ConditionalOnProperty(
    value = {"widiazine.xxljob.enabled"},
    havingValue = "true",
    matchIfMissing = true
)
public class XxlJobConfiguration {

    @Bean
    @ConditionalOnClass
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
        xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppname());
        xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
        xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
        return xxlJobSpringExecutor;
    }
}

Nacos 配置

在 Nacos 中配置(widiazine-{module}.yaml):

widiazine:
  xxljob:
    enabled: true
    adminAddresses: @config.xxljob.adminAddresses@
    appname: @config.xxljob.appname@
    accessToken: @config.xxljob.accessToken@
    logPath: @config.xxljob.logPath@
    logRetentionDays: 30

验证配置

启动应用后,在 XXL-JOB 管理中心的「执行器管理」中应该能看到注册的执行器:

执行器名称执行器地址在线状态
widiazine-cloud-system192.168.1.100:9999在线

文档版本: 1.0.0

本页目录