SpringBoot集成Xxljob 1.9.0 实现定时任务

一,引入依赖


        
            com.xuxueli
            xxl-job-core
            1.9.0
        

二、属性配置

#xxjob定时任务
xxl:
  job:
    admin:
      addresses: http://ip:port    //xxjob后台管理地址
    executor:
      ip:
      port: 19904    
      logpath: /data/logs/xxl-job/follow-assets-executor
      appname: follow-assets-executor
    accessToken:
    logRetentionDays: 3

三、配置类

@Configuration
public class XxjobFollowAssetsConfig {

    @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.logRetentionDays}")
    private int logRetentionDays;

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

    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobExecutor xxlJobExecutor() {
        XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
        xxlJobExecutor.setIp(ip);
        xxlJobExecutor.setPort(port);
        xxlJobExecutor.setAppName(appName);
        xxlJobExecutor.setAdminAddresses(adminAddresses);
        xxlJobExecutor.setLogPath(logPath);
        xxlJobExecutor.setAccessToken(accessToken);
        xxlJobExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobExecutor;
    }

}

四、调度执行类

@Component
@JobHandler("followUnwindJobHandler")
public class FollowUnwindJobHandler extends IJobHandler {

    @Override
    public ReturnT execute(String s) throws Exception {
        XxlJobLogger.log("FollowUnwindJobHandler start");
        //todo  执行逻辑
        XxlJobLogger.log("FollowUnwindJobHandler end");
        return ReturnT.SUCCESS;
    }
}

五、管理后台配置(此处省略)

       1、执行器配置

       2、任务配置

你可能感兴趣的:(SpringBoot)