<dependency>
<groupId>com.xxl-job</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.2.0</version>
</dependency>
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.exception.XxlJobException;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldJob extends IJobHandler {
@XxlJob("helloWorldJobHandler")
public void execute() throws XxlJobException {
XxlJobHelper.log("Hello, XXL Job!");
// ...
XxlJobHelper.handleSuccess();
}
}
properties
# xxljob admin addresses
xxl.job.admin.addresses=http://localhost:8080/xxl-job-admin
# xxljob executor
xxl.job.executor.appname=my-job-app
xxl.job.executor.address=http://localhost:9999/xxl-job-executor
xxl.job.executor.ip=
xxl.job.executor.port=9999
import com.xxl.job.core.executor.XxlJobExecutor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
// start xxl-job executor
XxlJobExecutor.run(App.class, args);
}
}