下载 xxl-job xxl-job
安装步骤初始换项目
文档链接 项目部署文档
找打启动类启动项目,可以把不必要的两个实例删除掉 也可不删
部署成功后 输入网址: http://localhost:8081/xxl-job-admin/ 默认端口号为8080 我这里改了,因为我的项目占用的这个端口号
调度中心访问地址:http://localhost:8081/xxl-job-admin (该地址执行器将会使用到,作为回调地址)
默认登录账号 “admin/123456”
, 登录后运行界面如下图所示。
项目依赖
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
编写配置文件
xxl:
job:
accessToken: default_token
admin:
addresses: http://127.0.0.1:8081/xxl-job-admin
executor:
appname: xxl-job-hhh
address:
ip: 0.0.0.0
port: 9999
logpath: D:/logs/applogs/xxl-job.log
logretentiondays: 30
创建配置类
@Configuration
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address}")
private String address;
@Value("${xxl.job.executor.ip}")
private String ip;
@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
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info("初始化 xxl-job 配置成功");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
启动项目会立即注入到xxl-job 后天界面
其中
这两处的AppName要一致,不一致可能不成功
如下图我创建了两个不同的任务
都能正常执行