第一次用bladex (看官方文档就出不来那种).
1. 定时任务坑(xxljob)
明明已经按照文档书写:
- 创建一个类 .
- 类中定义一个方法,方法上添加
@XxlJob("xxx")
- 在xxljob的服务中配置 我们定义的 handler名称->
xxx
- 启动测试
但是还是报job handler [xxx] not found.
原因: 我们没有注册执行器
解决
- 我们的服务中心,新建配置类
package com.aiotxip.cotton.config;import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class XxlJobConfig {private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);@Value("${xxl.job.admin.addresses}")private String adminAddresses;@Value("${xxl.job.executor.appname}")private String appName;@Value("${xxl.job.executor.ip}")private String ip;@Value("${xxl.job.executor.port}")private int port;@Value("${xxl.job.accessToken}")private String accessToken;@Value("${xxl.job.executor.logpath}")private String logPath;@Value("${xxl.job.executor.logretentiondays}")private int logRetentionDays;@Beanpublic XxlJobSpringExecutor xxlJobExecutor() {logger.info(">>>>>>>>>>> xxl-job config init.");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppName(appName);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;}}
- 在yml中配置参数
xxl: job: accessToken: '' admin: addresses: http://localhost:7009/xxl-job-admin executor: appname: blade-xxljob ip: 127.0.0.1 logpath: ../data/applogs/xxl-job/jobhandler logretentiondays: -1 port: 7038
注意端口port不能和已有的冲突(可能其他服务也注册有)
3. 重启项目,执行,还是失败.(如果这一步已经成功了就无需往下看了).
因为我们定时任务对应的执行器不对.需要编辑我们的定时任务
4. 再次执行,执行成功.
来源地址:https://blog.csdn.net/weixin_42452726/article/details/127803097