Find annotations on implemented generic interface methods as well

Issue: SPR-16060
This commit is contained in:
Juergen Hoeller
2018-07-18 19:44:30 +02:00
parent c77dbbb1e6
commit 23d4862017
2 changed files with 43 additions and 7 deletions

View File

@@ -39,6 +39,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -588,8 +589,7 @@ public abstract class AnnotationUtils {
Set<Method> annotatedMethods = getAnnotatedMethodsInBaseType(ifc);
if (!annotatedMethods.isEmpty()) {
for (Method annotatedMethod : annotatedMethods) {
if (annotatedMethod.getName().equals(method.getName()) &&
Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())) {
if (isOverride(method, annotatedMethod)) {
A annotation = getAnnotation(annotatedMethod, annotationType);
if (annotation != null) {
return annotation;
@@ -647,6 +647,23 @@ public abstract class AnnotationUtils {
return true;
}
private static boolean isOverride(Method method, Method candidate) {
if (!candidate.getName().equals(method.getName()) ||
candidate.getParameterCount() != method.getParameterCount()) {
return false;
}
Class<?>[] paramTypes = method.getParameterTypes();
if (Arrays.equals(candidate.getParameterTypes(), paramTypes)) {
return true;
}
for (int i = 0; i < paramTypes.length; i++) {
if (paramTypes[i] != ResolvableType.forMethodParameter(candidate, i, method.getDeclaringClass()).resolve()) {
return false;
}
}
return true;
}
/**
* Find a single {@link Annotation} of {@code annotationType} on the
* supplied {@link Class}, traversing its interfaces, annotations, and