Bladeren bron

GLUE依赖注入逻辑优化,支持别名注入;from:shirokumacafe@github

xueli.xue 8 jaren geleden
bovenliggende
commit
4cf65ebdb2
2 gewijzigde bestanden met toevoegingen van 14 en 2 verwijderingen
  1. 1 0
      README.md
  2. 13 2
      xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java

+ 1 - 0
README.md Bestand weergeven

709
 - 5、升级数据库连接池c3p0版本;
709
 - 5、升级数据库连接池c3p0版本;
710
 - 6、执行器log4j配置优化,去除无效属性;
710
 - 6、执行器log4j配置优化,去除无效属性;
711
 - 7、底层代码重构和逻辑优化以及CleanCode;
711
 - 7、底层代码重构和逻辑优化以及CleanCode;
712
+- 8、GLUE依赖注入逻辑优化,支持别名注入;
712
 
713
 
713
 
714
 
714
 #### 规划中
715
 #### 规划中

+ 13 - 2
xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java Bestand weergeven

8
 import org.slf4j.LoggerFactory;
8
 import org.slf4j.LoggerFactory;
9
 import org.springframework.beans.BeansException;
9
 import org.springframework.beans.BeansException;
10
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.beans.factory.annotation.Qualifier;
11
 import org.springframework.context.ApplicationContext;
12
 import org.springframework.context.ApplicationContext;
12
 import org.springframework.context.ApplicationContextAware;
13
 import org.springframework.context.ApplicationContextAware;
13
 import org.springframework.core.annotation.AnnotationUtils;
14
 import org.springframework.core.annotation.AnnotationUtils;
76
 			// with bean-id, bean could be found by both @Resource and @Autowired, or bean could only be found by @Autowired
77
 			// with bean-id, bean could be found by both @Resource and @Autowired, or bean could only be found by @Autowired
77
 			if (AnnotationUtils.getAnnotation(field, Resource.class) != null) {
78
 			if (AnnotationUtils.getAnnotation(field, Resource.class) != null) {
78
 				try {
79
 				try {
79
-					fieldBean = applicationContext.getBean(field.getName());
80
+					Resource resource = AnnotationUtils.getAnnotation(field, Resource.class);
81
+					if (resource.name()!=null && resource.name().length()>0){
82
+						fieldBean = applicationContext.getBean(resource.name());
83
+					} else {
84
+						fieldBean = applicationContext.getBean(field.getName());
85
+					}
80
 				} catch (Exception e) {
86
 				} catch (Exception e) {
81
 				}
87
 				}
82
 				if (fieldBean==null ) {
88
 				if (fieldBean==null ) {
83
 					fieldBean = applicationContext.getBean(field.getType());
89
 					fieldBean = applicationContext.getBean(field.getType());
84
 				}
90
 				}
85
 			} else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) {
91
 			} else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) {
86
-				fieldBean = applicationContext.getBean(field.getType());		
92
+				Qualifier qualifier = AnnotationUtils.getAnnotation(field, Qualifier.class);
93
+				if (qualifier!=null && qualifier.value()!=null && qualifier.value().length()>0) {
94
+					fieldBean = applicationContext.getBean(qualifier.value());
95
+				} else {
96
+					fieldBean = applicationContext.getBean(field.getType());
97
+				}
87
 			}
98
 			}
88
 			
99
 			
89
 			if (fieldBean!=null) {
100
 			if (fieldBean!=null) {