Backend Development 16 min read

Integrating Spring Boot with XXL-Job for Distributed Task Scheduling

This article explains how to integrate Spring Boot with the open‑source XXL‑Job distributed task scheduler, covering XXL‑Job fundamentals, configuration of the admin console and executor, Maven dependencies, property settings, code examples, @XxlJob annotation parameters, best practices, and includes additional promotional material.

Top Architect
Top Architect
Top Architect
Integrating Spring Boot with XXL-Job for Distributed Task Scheduling

In modern applications, scheduled tasks are indispensable, and the combination of Spring Boot and XXL‑Job offers a powerful toolset for simplifying task scheduling and management.

XXL‑Job is an open‑source distributed task scheduling platform built on Java, providing features such as distributed execution, elastic scaling, a centralized scheduling console, multiple task types (cron, Bean, Shell, HTTP, GLUE), task dependencies, failure retries, alerting, logging, and active community support.

The article compares XXL‑Job with other solutions like Quartz, Spring’s @Scheduled, Elastic‑Job, Akka Scheduler, and Cron4J, highlighting XXL‑Job’s advantages in visual management, distributed support, and alert mechanisms.

Integration steps: Clone the XXL‑Job source from Gitee or GitHub, execute the provided /xxl-job/doc/db/tables_xxl_job.sql script, and modify the admin console configuration in /xxl-job/xxl-job-admin/src/main/resources/application.properties . Example configuration (port, datasource, access token) is shown in a code block.

server.port=9998
spring.datasource.url=jdbc:mysql://127.0.0.1:3361/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
xxl.job.accessToken=eyJhbGciOiJIUzI1NiJ9

After configuring the admin console, access it at http://127.0.0.1:9998/xxl-job-admin with the default credentials.

Executor configuration: Add the Maven dependency com.xuxueli:xxl-job-core:2.4.0 to your project, set the executor properties (admin address, app name, IP, port, token, log path, retention days) in application.properties , and create a Spring bean to initialize XxlJobSpringExecutor . The Java configuration class is provided:

package com.todoitbo.baseSpringbootDasmart.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class XxlJobConfig {
    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;
    @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.accesstoken}")
    private String accessToken;
    @Value("${xxl.job.executor.logpath}")
    private String logPath;
    @Value("${xxl.job.executor.logretentiondays}")
    private int logRetentionDays;

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

A sample job handler is also shown, using the @XxlJob("demoJobHandler") annotation to define a task:

package com.todoitbo.baseSpringbootDasmart.handler;

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

@Component
public class JobHandler {
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello World.");
    }
}

The article explains the three basic parameters of the @XxlJob annotation— value (task name), init (initialization method), and destroy (cleanup method)—and how they are used.

Best practices: detailed logging, parameter validation, idempotent task design, failure handling strategies, task dependencies, dynamic scheduling, monitoring and alert integration, version control, unit testing, clustering, security of the admin console, and proper documentation and training.

Finally, the article contains promotional sections offering ChatGPT services, a paid community, and various marketing links, which are unrelated to the technical tutorial.

distributed systemsJavabackend developmenttask schedulingSpring Bootxxl-job
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.