Ver código fonte

springboot版本执行器,取消XML配置,改为类配置方式; ( From github user:FelixXu )

xuxueli 8 anos atrás
pai
commit
7e651b5504

+ 1 - 0
doc/XXL-JOB官方文档.md Ver arquivo

@@ -867,6 +867,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
867 867
 - 6、执行器重复注册问题修复;
868 868
 - 7、任务线程轮空30次后自动销毁,降低低频任务的无效线程消耗。
869 869
 - 8、执行器任务执行结果批量回调,降低回调频率提升执行器性能;
870
+- 9、springboot版本执行器,取消XML配置,改为类配置方式;
870 871
 
871 872
 #### TODO LIST
872 873
 - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;

+ 37 - 2
xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java Ver arquivo

@@ -1,11 +1,46 @@
1 1
 package com.xxl.job.executor.core.config;
2 2
 
3
+import com.xxl.job.core.executor.XxlJobExecutor;
4
+import org.slf4j.Logger;
5
+import org.slf4j.LoggerFactory;
6
+import org.springframework.beans.factory.annotation.Value;
7
+import org.springframework.context.annotation.Bean;
8
+import org.springframework.context.annotation.ComponentScan;
3 9
 import org.springframework.context.annotation.Configuration;
4
-import org.springframework.context.annotation.ImportResource;
5 10
 
6 11
 
7 12
 @Configuration
8
-@ImportResource("classpath:applicationcontext-xxl-job.xml")
13
+@ComponentScan(basePackages = "com.xxl.job.executor.service.jobhandler")
9 14
 public class XxlJobConfig {
15
+    private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
16
+
17
+
18
+    @Value("${xxl.job.admin.addresses}")
19
+    private String addresses;
20
+
21
+    @Value("${xxl.job.executor.appname}")
22
+    private String appname;
23
+
24
+    @Value("${xxl.job.executor.ip}")
25
+    private String ip;
26
+
27
+    @Value("${xxl.job.executor.port}")
28
+    private int port;
29
+
30
+    @Value("${xxl.job.executor.logpath}")
31
+    private String logpath;
32
+
33
+
34
+    @Bean(initMethod = "start", destroyMethod = "destroy")
35
+    public XxlJobExecutor xxlJobExecutor() {
36
+        logger.error("------------ xxlJobExecutor -----------");
37
+        XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
38
+        xxlJobExecutor.setIp(ip);
39
+        xxlJobExecutor.setPort(port);
40
+        xxlJobExecutor.setAppName(appname);
41
+        xxlJobExecutor.setAdminAddresses(addresses);
42
+        xxlJobExecutor.setLogPath(logpath);
43
+        return xxlJobExecutor;
44
+    }
10 45
 
11 46
 }

+ 1 - 1
xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java Ver arquivo

@@ -12,7 +12,7 @@ public class IndexController {
12 12
     @RequestMapping("/")
13 13
     @ResponseBody
14 14
     String index() {
15
-        return "xxl job is running.";
15
+        return "xxl job executor running.";
16 16
     }
17 17
 
18 18
 }

+ 9 - 0
xxl-job-executor-springboot-example/src/main/resources/application.properties Ver arquivo

@@ -4,5 +4,14 @@ server.port=8081
4 4
 # log config
5 5
 logging.config=classpath:logback.xml
6 6
 
7
+# xxl-job
8
+### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
9
+xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
7 10
 
11
+### xxl-job executor address
12
+xxl.job.executor.appname=xxl-job-executor-example
13
+xxl.job.executor.ip=
14
+xxl.job.executor.port=9999
8 15
 
16
+### xxl-job log path
17
+xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/

+ 0 - 39
xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml Ver arquivo

@@ -1,39 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<beans xmlns="http://www.springframework.org/schema/beans"
3
-	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
-	   xmlns:context="http://www.springframework.org/schema/context"
5
-	   xsi:schemaLocation="http://www.springframework.org/schema/beans
6
-           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7
-           http://www.springframework.org/schema/context
8
-           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
9
-
10
-	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
11
-		<property name="fileEncoding" value="utf-8" />
12
-		<property name="locations">
13
-			<list>
14
-				<value>classpath*:xxl-job-executor.properties</value>
15
-			</list>
16
-		</property>
17
-	</bean>
18
-
19
-	<!-- ********************************* 基础配置 ********************************* -->
20
-
21
-	<!-- 配置01、JobHandler 扫描路径 -->
22
-	<context:component-scan base-package="com.xxl.job.executor.service.jobhandler" />
23
-
24
-	<!-- 配置02、执行器 -->
25
-	<bean id="xxlJobExecutor" class="com.xxl.job.core.executor.XxlJobExecutor" init-method="start" destroy-method="destroy" >
26
-		<!-- 执行器IP[选填],为空则自动获取 -->
27
-		<property name="ip" value="${xxl.job.executor.ip}" />
28
-		<!-- 执行器端口号[必须] -->
29
-		<property name="port" value="${xxl.job.executor.port}" />
30
-		<!-- 执行器AppName[选填],为空则关闭自动注册 -->
31
-		<property name="appName" value="${xxl.job.executor.appname}" />
32
-		<!-- 执行器注册中心地址[选填],为空则关闭自动注册 -->
33
-		<property name="adminAddresses" value="${xxl.job.admin.addresses}" />
34
-		<!-- 执行器日志路径[必填] -->
35
-		<property name="logPath" value="${xxl.job.executor.logpath}" />
36
-	</bean>
37
-
38
-
39
-</beans>

+ 0 - 10
xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties Ver arquivo

@@ -1,10 +0,0 @@
1
-### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
2
-xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
3
-
4
-### xxl-job executor address
5
-xxl.job.executor.appname=xxl-job-executor-example
6
-xxl.job.executor.ip=
7
-xxl.job.executor.port=9999
8
-
9
-### xxl-job log path
10
-xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/