[XXL-JOB] 项目集成-Framework
<dependency> <groupId>com.hbasesoft.framework</groupId> <artifactId>framework-job-core</artifactId> </dependency> <dependency> <groupId>com.hbasesoft.framework</groupId> <artifactId>framework-job-xxl</artifactId> </dependency>
job.enable: true # 是否启用
job.xxl.admin.addresses: http://*****/xxl-job-admin # xxl-job地址
job.xxl.accessToken: # token 选填
job.xxl.executor.appname: mbp-job # 定时任务执行器名称
job.xxl.executor.port: 9999
job.xxl.executor.logpath: /data/logs/java/mbp-job #日志
job.xxl.executor.logretentiondays: 30
package com.tlc.cms.job; import com.hbasesoft.framework.common.utils.ContextHolder; import com.hbasesoft.framework.common.utils.logger.LoggerUtil; import com.hbasesoft.framework.job.core.JobContext; import com.hbasesoft.framework.job.core.SimpleJob; import com.hbasesoft.framework.job.core.annotation.Job; import com.tlc.cms.entity.CmsAdEntity; import com.tlc.cms.service.CmsAdService; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; // 1: 添加Job注解 @Job(name = "cmsAdJob", cron = "0 0 1 * * ?") public class CmsAdJob implements SimpleJob { private CmsAdService cmsService; // 2: 如果想要在该类内部引用其他Bean,需通过此方法获取Bean对象,不可直接使用注解注入对象 protected CmsAdService getCmsAdService() { if (cmsService == null) { cmsService = ContextHolder.getContext().getBean(CmsAdService.class); } return cmsService; } @Override public void execute(final JobContext jobContext) { LoggerUtil.info("===================定时任务开始=================="); /** 此处写自己的定时任务逻辑代码 */ LoggerUtil.info("===================定时任务结束=================="); } }
配置完后保存。
2、配置任务
可手动触发任务执行。