官网地址:https://www.xuxueli.com/xxl-job

一、搭建好xxlJob平台,一般都已经搭建完毕

二、接入xxljob的步骤

  1. 引入依赖

    1. <dependency>
    2. <groupId>com.xuxueli</groupId>
    3. <artifactId>xxl-job-core</artifactId>
    4. <version>2.0.1</version>
    5. </dependency>
  2. 在application.properties或者application.yml 中添加xxljob的相关配置

    1. #xxlJob
    2. ### 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
    3. xxl.job.admin.addresses=http://xxl-job:8080/xxl-job-admin/
    4. ### 执行器通讯TOKEN [选填]:非空时启用;
    5. xxl.job.admin.accessToken=
    6. ### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
    7. xxl.job.admin.appname= fantasyci-xxl-job
    8. ### 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
    9. xxl.job.admin.ip=
    10. ### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
    11. xxl.job.admin.port=9999
    12. ### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
    13. xxl.job.admin.logpath=root/logs/xxl-job/jobhandler
    14. ### 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
    15. xxl.job.admin.logretentiondays=30
  3. 写一个配置类,进行读取xxljsob中的配置 ```java package qa.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;

/**

  • @author Alex
  • @date 2021/9/18 5:18 下午
  • */ @Slf4j @Data @Configuration @ConditionalOnProperty(

    1. prefix = "xxl.job.admin",
    2. name = {"addresses"}

    ) @ConfigurationProperties(prefix = “xxl.job.admin”) public class XxlJobConfiguration { private String addresses; private String appName; private String ip; private int port; private String accessToken; private String logPath; private int logRetentionDays;

    @Bean(

    1. initMethod = "start",
    2. destroyMethod = "destroy"

    ) public XxlJobSpringExecutor xxlJobSpringExecutor() {

    1. log.info(">>>>>>>>>>> xxl-job config init...");
    2. XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
    3. xxlJobSpringExecutor.setAdminAddresses(this.addresses);
    4. xxlJobSpringExecutor.setAppName(this.appName);
    5. xxlJobSpringExecutor.setIp(this.ip);
    6. xxlJobSpringExecutor.setPort(this.port);
    7. xxlJobSpringExecutor.setAccessToken(this.accessToken);
    8. xxlJobSpringExecutor.setLogPath(this.logPath);
    9. xxlJobSpringExecutor.setLogRetentionDays(this.logRetentionDays);
    10. return xxlJobSpringExecutor;

    } }

  1. 3. bean模式,编写一个job,新建一个task包,新建一个FlowHandler
  2. ```java
  3. @Slf4j
  4. @JobHandler("runFlowHandler")
  5. @Service
  6. public class FlowHandler extends IJobHandler {
  7. @Autowired
  8. private SuiteService suiteService;
  9. @Override
  10. public ReturnT<String> execute(String s) {
  11. suiteService.runTestSuite("fantasyrn_flow.xml", "fantasy", "0000,0001", "no_baranch", "");
  12. return ReturnT.SUCCESS;
  13. }
  14. }
  1. 按照官网去操作即可了