Springboot + xxlJob注意事项

1. 部署

就是这个地址: https://gitee.com/xuxueli0323/xxl-job
由于xxl-job的思想是 调度中心负责调度任务,然后有执行器负责接受调度的信息,然后根据调度,执行任务中的具体逻辑

将 xl-job-admin 启动起来,操作xl-job-admin这个文件夹下的配置文件即可:

创建数据库
执行sql文件
修改yml配置
启动这个服务
访问,http://127.0.0.1:8080/xxl-job-admin/
并登录 admin/123456


2.SpringBoot集成

1引入xxl-job核心依赖
   <dependency>
            <groupId>com.xuxueli</groupId>
            <artifactId>xxl-job-core</artifactId>
            <version>2.3.1</version>
        </dependency>


2 创建服务,配置yml


xxl.job.admin.addresses = http://127.0.0.1:8080/xxl-job-admin
xxl.job.executor.port = 9999
xxl.job.executor.appname = xxljob
xxl.job.executor.logpath = /data/applogs/xxl-job/jobhandler
xxl.job.executor.logretentiondays = 30

3 配置job

@Slf4j
@Configuration
public class XxlJobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${xxl.job.executor.appname}")
    private String appName;

    @Value("${xxl.job.executor.port}")
    private int port;

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

    @Value("${xxl.job.executor.logretentiondays}")
    private int logRetentionDays;

    @Bean
    @ConditionalOnExpression("${xxl-job.enabled:true}")
    public XxlJobSpringExecutor xxlJobSpringExecutor() {
        log.info("xxl-job config init =====");
        XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
        executor.setAdminAddresses(adminAddresses);
        executor.setAppname(appName);
        executor.setPort(port);
        executor.setLogPath(logPath);
        executor.setLogRetentionDays(logRetentionDays);
        return executor;
    }
}

4 测试

@Component
public class TestJob {

    // 测试xxlJob是否配置成功
    @XxlJob(value = "firstTestJob")
    public ReturnT<String> firstTestJob(String param){
        System.out.println("执行触发器:"+param);
        return ReturnT.SUCCESS;
    }

}
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值