Skip to content

SPR-17223 - Support for methods that are declared in interfaces and implemented in super class #1950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public static boolean isFinalizeMethod(@Nullable Method method) {
*/
public static Method getMostSpecificMethod(Method method, @Nullable Class<?> targetClass) {
Class<?> specificTargetClass = (targetClass != null ? ClassUtils.getUserClass(targetClass) : null);
Class<?>[] interfaces = targetClass.getInterfaces();
for (Class<?> itf : interfaces) {
Method mostSpecificMethod = getMostSpecificMethod(method, itf);
if (!method.equals(mostSpecificMethod))
return mostSpecificMethod;
}
Method resolvedMethod = ClassUtils.getMostSpecificMethod(method, specificTargetClass);
// If we are dealing with method with generic parameters, find the original method.
return BridgeMethodResolver.findBridgedMethod(resolvedMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public static <A extends Annotation> A findAnnotation(Method method, @Nullable C
}

@Nullable
private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class<?>... ifcs) {
public static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class<?>... ifcs) {
for (Class<?> ifc : ifcs) {
Set<Method> annotatedMethods = getAnnotatedMethodsInBaseType(ifc);
if (!annotatedMethods.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ private List<Annotation[][]> getInterfaceParameterAnnotations() {
List<Annotation[][]> parameterAnnotations = this.interfaceParameterAnnotations;
if (parameterAnnotations == null) {
parameterAnnotations = new ArrayList<>();
for (Class<?> ifc : this.beanType.getInterfaces()) {
for (Method candidate : ifc.getMethods()) {
if (isOverrideFor(candidate)) {
parameterAnnotations.add(candidate.getParameterAnnotations());
}
}
}
for (Class<?> ifc : this.method.getDeclaringClass().getInterfaces()) {
for (Method candidate : ifc.getMethods()) {
if (isOverrideFor(candidate)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ protected boolean isHandler(Class<?> beanType) {
@Nullable
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = createRequestMappingInfo(method);
if (info == null) {
info = createRequestMappingInfo(method, handlerType.getInterfaces());
}
if (info != null) {
RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
if (typeInfo != null) {
Expand Down