依赖:
配置类:
@Configuration
public class XxlJobConfig{
private Loggerlogger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private StringadminAddresses;
@Value("${xxl.job.executor.appname}")
private Stringappname;
@Value("${xxl.job.executor.ip}")
private Stringip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.executor.logpath}")
private StringlogPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean(initMethod ="start", destroyMethod ="destroy")
public XxlJobExecutorxxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobExecutor xxlJobExecutor =new XxlJobExecutor();
xxlJobExecutor.setAdminAddresses(adminAddresses);
xxlJobExecutor.setAppName(appname);
//xxlJobSpringExecutor.setAddress(address);
xxlJobExecutor.setIp(ip);
xxlJobExecutor.setPort(port);
//xxlJobExecutor.setAccessToken(accessToken);
xxlJobExecutor.setLogPath(logPath);
xxlJobExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobExecutor;
}
可以完整的复制。这里使用的是1.9.2的版本,高版本不再使用这个类。
xxl-job实现类:
@Component("testJob")
@JobHandler("testJob")
@Log
public class TestJobextends IJobHandler{
@Override
public ReturnT
log.info("===================================");
XxlJobLogger.log("======================");
return SUCCESS;
}
}
然后在xxl-job中配置即可。