Skip to content

Commit 6571e82

Browse files
authored
Fix the issue where MergedAnnotation is null when retrieved in Spring 5.x (#15581)
Added compatibility support for Spring 5.x in the method org.apache.dubbo.config.spring.util.AnnotationUtils#tryGetMergedAnnotation to ensure that MergedAnnotations can be correctly retrieved in Spring 5.x environments
1 parent 9eeae4d commit 6571e82

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

  • dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/AnnotationUtils.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -631,22 +631,30 @@ public static Annotation tryGetMergedAnnotation(
631631

632632
if (ClassUtils.isPresent(ANNOTATED_ELEMENT_UTILS_CLASS_NAME, classLoader)) {
633633
Class<?> annotatedElementUtilsClass = resolveClassName(ANNOTATED_ELEMENT_UTILS_CLASS_NAME, classLoader);
634-
// getMergedAnnotation method appears in the Spring Framework 4.2
635-
Method getMergedAnnotationMethod = findMethod(
636-
annotatedElementUtilsClass,
637-
"getMergedAnnotation",
638-
AnnotatedElement.class,
639-
Class.class,
640-
boolean.class,
641-
boolean.class);
634+
// getMergedAnnotation method appears in the Spring Framework 5.x
635+
Method getMergedAnnotationMethod =
636+
findMethod(annotatedElementUtilsClass, "getMergedAnnotation", AnnotatedElement.class, Class.class);
642637
if (getMergedAnnotationMethod != null) {
643-
mergedAnnotation = (Annotation) invokeMethod(
644-
getMergedAnnotationMethod,
645-
null,
646-
annotatedElement,
647-
annotationType,
648-
classValuesAsString,
649-
nestedAnnotationsAsMap);
638+
mergedAnnotation =
639+
(Annotation) invokeMethod(getMergedAnnotationMethod, null, annotatedElement, annotationType);
640+
} else {
641+
// getMergedAnnotation method appears in the Spring Framework 4.2
642+
getMergedAnnotationMethod = findMethod(
643+
annotatedElementUtilsClass,
644+
"getMergedAnnotation",
645+
AnnotatedElement.class,
646+
Class.class,
647+
boolean.class,
648+
boolean.class);
649+
if (getMergedAnnotationMethod != null) {
650+
mergedAnnotation = (Annotation) invokeMethod(
651+
getMergedAnnotationMethod,
652+
null,
653+
annotatedElement,
654+
annotationType,
655+
classValuesAsString,
656+
nestedAnnotationsAsMap);
657+
}
650658
}
651659
}
652660

0 commit comments

Comments
 (0)