1. 搭建步骤请参考xxl-job官方文档
2. 具体使用
-
引入依赖
<properties> <xxl-job-core.version>1.9.1</xxl-job-core.version> </properties> <dependencies> <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>${xxl-job-core.version}</version> <exclusions> <exclusion> <artifactId>groovy-all</artifactId> <groupId>org.codehaus.groovy</groupId> </exclusion> </exclusions> </dependency> </dependencies>
-
创建任务类 继承XxlJobHandler ,实现 doExecuteOnCompanyId()和parseParam()方法
@Component(value = "pushEnterpriseJob") @JobHandler(value = "pushEnterpriseJob") public class PushEnterpriseJob extends XxlJobHandler<JsonObject> { @Override protected void doExecuteOnCompanyId(Long aLong, JsonObject jsonObject, int i, int i1) throws Exception { // 编写业务逻辑 } } } @Override protected JsonObject parseParam(String s) { return null; } }
-
只需要在任务类上加上@Component和@JobHandler注解,spring容器在执行时,就会扫到该任务类,根据你在xxl-job平台的cron表达式设置的时间进行推送