Sfoglia il codice sorgente

XxlJob注解扫描方式优化,支持查找父类以及接口和基于类代理等常见情况

xuxueli 5 anni fa
parent
commit
3dd41db79e

+ 8 - 7
doc/XXL-JOB官方文档.md

@@ -1715,13 +1715,14 @@ public ReturnT<String> execute(String param) {
 - 9、调度中心国际化完善:新增 "中文繁体" 支持。默认为 "zh_CN"/中文简体, 可选范围为 "zh_CN"/中文简体, "zh_TC"/中文繁体 and "en"/英文;
 - 10、移除旧类注解JobHandler,推荐使用基于方法注解 "@XxlJob" 的方式进行任务开发;(如需保留类注解JobHandler使用方式,可以参考旧版逻辑定制开发);
 - 11、修复bootstrap.min.css.map 404问题;
-- 12、[迭代中]自定义失败重试时间间隔;
-- 13、[迭代中]任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息;
-- 14、[迭代中]新增执行器描述、任务描述属性;
-- 15、[迭代中]任务执行一次的时候指定IP;
-- 16、[迭代中]任务日志支持单个清理和状态转移,方便触发子任务;
-- 17、[迭代中]任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败;
-- 18、[迭代中]优雅停机回调丢失问题修复;
+- 12、XxlJob注解扫描方式优化,支持查找父类以及接口和基于类代理等常见情况;
+- 13、[迭代中]自定义失败重试时间间隔;
+- 14、[迭代中]任务复制功能;点击复制是弹出新建任务弹框,并初始化被复制任务信息;
+- 15、[迭代中]新增执行器描述、任务描述属性;
+- 16、[迭代中]任务执行一次的时候指定IP;
+- 17、[迭代中]任务日志支持单个清理和状态转移,方便触发子任务;
+- 18、[迭代中]任务结果丢失处理:针对长期处于运行中的任务(设置过期时间时,运行超过"过期时间+1min";未设置超时时间时,运行超过"30min"),主动检测该执行器是否在线,如果不在线主动标记失败;
+- 19、[迭代中]优雅停机回调丢失问题修复;
 
 
 ### TODO LIST

+ 6 - 7
xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java

@@ -16,8 +16,6 @@ import org.springframework.core.MethodIntrospector;
 import org.springframework.core.annotation.AnnotatedElementUtils;
 
 import java.lang.reflect.Method;
-
-import java.util.HashMap;
 import java.util.Map;
 
 
@@ -81,12 +79,11 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
             return;
         }
         // init job handler from method
-
         String[] beanDefinitionNames = applicationContext.getBeanNamesForType(Object.class, false, true);
         for (String beanDefinitionName : beanDefinitionNames) {
             Object bean = applicationContext.getBean(beanDefinitionName);
 
-            Map<Method, XxlJob> annotatedMethods = new HashMap<>();
+            Map<Method, XxlJob> annotatedMethods = null;   // referred to :org.springframework.context.event.EventListenerMethodProcessor.processBean
             try {
                 annotatedMethods = MethodIntrospector.selectMethods(bean.getClass(),
                         new MethodIntrospector.MetadataLookup<XxlJob>() {
@@ -96,9 +93,10 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
                             }
                         });
             } catch (Throwable ex) {
-                if (logger.isDebugEnabled()) {
-                    logger.debug("Could not resolve methods for bean with name '" + beanDefinitionName + "'", ex);
-                }
+                logger.debug("xxl-job method-jobhandler resolve error for bean[" + beanDefinitionName + "].", ex);
+            }
+            if (annotatedMethods==null || annotatedMethods.isEmpty()) {
+                continue;
             }
 
             for (Map.Entry<Method, XxlJob> methodXxlJobEntry : annotatedMethods.entrySet()) {
@@ -107,6 +105,7 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
                 if (xxlJob == null) {
                     continue;
                 }
+
                 String name = xxlJob.value();
                 if (name.trim().length() == 0) {
                     throw new RuntimeException("xxl-job method-jobhandler name invalid, for[" + bean.getClass() + "#" + method.getName() + "] .");