From 7e651b55042d181c7cf11ebf5f4cd370912da500 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Thu, 29 Jun 2017 23:01:43 +0800 Subject: [PATCH] =?UTF-8?q?springboot=E7=89=88=E6=9C=AC=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=99=A8=EF=BC=8C=E5=8F=96=E6=B6=88XML=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=E7=B1=BB=E9=85=8D=E7=BD=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=9B=20=EF=BC=88=20From=20github=20user=EF=BC=9AF?= =?UTF-8?q?elixXu=20=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 1 + .../executor/core/config/XxlJobConfig.java | 39 ++++++++++++++++++- .../executor/mvc/handler/IndexController.java | 2 +- .../src/main/resources/application.properties | 9 +++++ .../resources/applicationcontext-xxl-job.xml | 39 ------------------- .../resources/xxl-job-executor.properties | 10 ----- 6 files changed, 48 insertions(+), 52 deletions(-) delete mode 100644 xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml delete mode 100644 xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 0ff1e823..4f99c104 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -867,6 +867,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 6、执行器重复注册问题修复; - 7、任务线程轮空30次后自动销毁,降低低频任务的无效线程消耗。 - 8、执行器任务执行结果批量回调,降低回调频率提升执行器性能; +- 9、springboot版本执行器,取消XML配置,改为类配置方式; #### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java index 4a8c1dae..1b075771 100644 --- a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java @@ -1,11 +1,46 @@ package com.xxl.job.executor.core.config; +import com.xxl.job.core.executor.XxlJobExecutor; +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.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; @Configuration -@ImportResource("classpath:applicationcontext-xxl-job.xml") +@ComponentScan(basePackages = "com.xxl.job.executor.service.jobhandler") public class XxlJobConfig { + private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); + + + @Value("${xxl.job.admin.addresses}") + private String addresses; + + @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.executor.logpath}") + private String logpath; + + + @Bean(initMethod = "start", destroyMethod = "destroy") + public XxlJobExecutor xxlJobExecutor() { + logger.error("------------ xxlJobExecutor -----------"); + XxlJobExecutor xxlJobExecutor = new XxlJobExecutor(); + xxlJobExecutor.setIp(ip); + xxlJobExecutor.setPort(port); + xxlJobExecutor.setAppName(appname); + xxlJobExecutor.setAdminAddresses(addresses); + xxlJobExecutor.setLogPath(logpath); + return xxlJobExecutor; + } } \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java index eba298eb..067f9c75 100644 --- a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java @@ -12,7 +12,7 @@ public class IndexController { @RequestMapping("/") @ResponseBody String index() { - return "xxl job is running."; + return "xxl job executor running."; } } \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/resources/application.properties b/xxl-job-executor-springboot-example/src/main/resources/application.properties index 3d944535..dc2a1b06 100644 --- a/xxl-job-executor-springboot-example/src/main/resources/application.properties +++ b/xxl-job-executor-springboot-example/src/main/resources/application.properties @@ -4,5 +4,14 @@ server.port=8081 # log config logging.config=classpath:logback.xml +# xxl-job +### xxl-job admin address list, such as "http://address" or "http://address01,http://address02" +xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin +### xxl-job executor address +xxl.job.executor.appname=xxl-job-executor-example +xxl.job.executor.ip= +xxl.job.executor.port=9999 +### xxl-job log path +xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/ diff --git a/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml deleted file mode 100644 index d72a087a..00000000 --- a/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - classpath*:xxl-job-executor.properties - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties b/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties deleted file mode 100644 index 2cd00d07..00000000 --- a/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties +++ /dev/null @@ -1,10 +0,0 @@ -### xxl-job admin address list, such as "http://address" or "http://address01,http://address02" -xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin - -### xxl-job executor address -xxl.job.executor.appname=xxl-job-executor-example -xxl.job.executor.ip= -xxl.job.executor.port=9999 - -### xxl-job log path -xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/ \ No newline at end of file