From 4cf65ebdb246c6f2c76a403086b539c40e8dde87 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Fri, 24 Feb 2017 22:02:46 +0800 Subject: [PATCH] =?UTF-8?q?GLUE=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=AB=E5=90=8D=E6=B3=A8=E5=85=A5=EF=BC=9Bfrom=EF=BC=9Ashiro?= =?UTF-8?q?kumacafe@github?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../java/com/xxl/job/core/glue/GlueFactory.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ca46b88..ffa438f3 100644 --- a/README.md +++ b/README.md @@ -709,6 +709,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 5、升级数据库连接池c3p0版本; - 6、执行器log4j配置优化,去除无效属性; - 7、底层代码重构和逻辑优化以及CleanCode; +- 8、GLUE依赖注入逻辑优化,支持别名注入; #### 规划中 diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java index 922daf9b..e9f04502 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.annotation.AnnotationUtils; @@ -76,14 +77,24 @@ public class GlueFactory implements ApplicationContextAware { // with bean-id, bean could be found by both @Resource and @Autowired, or bean could only be found by @Autowired if (AnnotationUtils.getAnnotation(field, Resource.class) != null) { try { - fieldBean = applicationContext.getBean(field.getName()); + Resource resource = AnnotationUtils.getAnnotation(field, Resource.class); + if (resource.name()!=null && resource.name().length()>0){ + fieldBean = applicationContext.getBean(resource.name()); + } else { + fieldBean = applicationContext.getBean(field.getName()); + } } catch (Exception e) { } if (fieldBean==null ) { fieldBean = applicationContext.getBean(field.getType()); } } else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) { - fieldBean = applicationContext.getBean(field.getType()); + Qualifier qualifier = AnnotationUtils.getAnnotation(field, Qualifier.class); + if (qualifier!=null && qualifier.value()!=null && qualifier.value().length()>0) { + fieldBean = applicationContext.getBean(qualifier.value()); + } else { + fieldBean = applicationContext.getBean(field.getType()); + } } if (fieldBean!=null) {