|
|
|
|
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) {
|