⬆️ 由于xxl-job2.1.2版本导致的懒加载提前问题,暂时升级到2.2.0快照版本
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.your.packages.admin.modules.test;
|
||||
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import com.xxl.job.core.handler.annotation.JobHandler;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import com.xxl.job.core.log.XxlJobLogger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -11,21 +10,19 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* 任务Handler示例(Bean模式)
|
||||
* XxlJob开发示例(Bean模式)
|
||||
*
|
||||
* 开发步骤:
|
||||
* 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”;
|
||||
* 2、注册到Spring容器:添加“@Component”注解,被Spring容器扫描为Bean实例;
|
||||
* 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。
|
||||
* 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
|
||||
* 1、在Spring Bean实例中,开发Job方法,方式格式要求为 "public ReturnT<String> execute(String param)"
|
||||
* 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
|
||||
* 3、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
|
||||
*
|
||||
* @author xuxueli 2015-12-19 19:43:36
|
||||
* @author xuxueli 2019-12-11 21:52:51
|
||||
*/
|
||||
@JobHandler(value="adminDemoJobHandler")
|
||||
@Component
|
||||
public class AdminDemoJobHandler extends IJobHandler {
|
||||
public class AdminDemoJobHandler {
|
||||
|
||||
@Override
|
||||
@XxlJob(value="adminDemoJobHandler")
|
||||
public ReturnT<String> execute(String param) throws Exception {
|
||||
XxlJobLogger.log("AdminDemoJobHandler Invoke Success.");
|
||||
|
||||
@@ -35,7 +32,7 @@ public class AdminDemoJobHandler extends IJobHandler {
|
||||
XxlJobLogger.log("beat at:" + i);
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
}
|
||||
return SUCCESS;
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.hccake.ballcat.api.modules.job;
|
||||
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import com.xxl.job.core.handler.annotation.JobHandler;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import com.xxl.job.core.log.XxlJobLogger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -11,21 +10,19 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* 任务Handler示例(Bean模式)
|
||||
* XxlJob开发示例(Bean模式)
|
||||
*
|
||||
* 开发步骤:
|
||||
* 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”;
|
||||
* 2、注册到Spring容器:添加“@Component”注解,被Spring容器扫描为Bean实例;
|
||||
* 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。
|
||||
* 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
|
||||
* 1、在Spring Bean实例中,开发Job方法,方式格式要求为 "public ReturnT<String> execute(String param)"
|
||||
* 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
|
||||
* 3、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
|
||||
*
|
||||
* @author xuxueli 2015-12-19 19:43:36
|
||||
* @author xuxueli 2019-12-11 21:52:51
|
||||
*/
|
||||
@JobHandler(value="apiDemoJobHandler")
|
||||
@Component
|
||||
public class ApiDemoJobHandler extends IJobHandler {
|
||||
public class ApiDemoJobHandler {
|
||||
|
||||
@Override
|
||||
@XxlJob("apiDemoJobHandler")
|
||||
public ReturnT<String> execute(String param) throws Exception {
|
||||
XxlJobLogger.log("ApiDemoJobHandler Invoke Success.");
|
||||
|
||||
@@ -35,7 +32,7 @@ public class ApiDemoJobHandler extends IJobHandler {
|
||||
XxlJobLogger.log("beat at:" + i);
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
}
|
||||
return SUCCESS;
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<mybatis-plus.version>3.3.1</mybatis-plus.version>
|
||||
<simple-cache.version>1.0.0</simple-cache.version>
|
||||
<swagger.core.version>1.5.2</swagger.core.version>
|
||||
<xxl-job.version>2.1.2</xxl-job.version>
|
||||
<xxl-job.version>2.2.0-SNAPSHOT</xxl-job.version>
|
||||
<spring-boot-admin.version>2.2.2</spring-boot-admin.version>
|
||||
<oss.aliyun.version>3.8.0</oss.aliyun.version>
|
||||
</properties>
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.hccake.ballcat.common.job;
|
||||
|
||||
import com.hccake.ballcat.common.job.properties.XxlJobProperties;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -13,13 +14,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
* <p>
|
||||
* xxl 初始化
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("com.hccake.ballcat.common.job.properties")
|
||||
@Import(XxlJobProperties.class)
|
||||
public class XxlJobAutoConfiguration {
|
||||
|
||||
@Bean(initMethod = "start", destroyMethod = "destroy")
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties) {
|
||||
log.info(">>>>>>>>>>> xxl-job config init.");
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdmin().getAddresses());
|
||||
xxlJobSpringExecutor.setAppName(xxlJobProperties.getExecutor().getAppName());
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.hccake.ballcat.common.job.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-09-18
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "xxl.job")
|
||||
public class XxlJobProperties {
|
||||
private XxlAdminProperties admin = new XxlAdminProperties();
|
||||
|
||||
Reference in New Issue
Block a user