Skip to content

Commit 5f5e5e9

Browse files
committed
support for methods that declared in interfaces and implemented in super
class
1 parent 454cd93 commit 5f5e5e9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public static <A extends Annotation> A findAnnotation(Method method, @Nullable C
556556
}
557557

558558
@Nullable
559-
private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class<?>... ifcs) {
559+
public static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class<?>... ifcs) {
560560
for (Class<?> ifc : ifcs) {
561561
Set<Method> annotatedMethods = getAnnotatedMethodsInBaseType(ifc);
562562
if (!annotatedMethods.isEmpty()) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.context.EmbeddedValueResolverAware;
3030
import org.springframework.core.annotation.AnnotatedElementUtils;
31+
import org.springframework.core.annotation.AnnotationUtils;
3132
import org.springframework.lang.Nullable;
3233
import org.springframework.stereotype.Controller;
3334
import org.springframework.util.Assert;
@@ -218,6 +219,9 @@ protected boolean isHandler(Class<?> beanType) {
218219
@Nullable
219220
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
220221
RequestMappingInfo info = createRequestMappingInfo(method);
222+
if (info == null) {
223+
info = createRequestMappingInfo(method, handlerType.getInterfaces());
224+
}
221225
if (info != null) {
222226
RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
223227
if (typeInfo != null) {
@@ -259,6 +263,17 @@ private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
259263
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
260264
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
261265
}
266+
267+
/**
268+
* support for methods that declared in interfaces and implemented in super class
269+
* @since 5.1
270+
*/
271+
@Nullable
272+
private RequestMappingInfo createRequestMappingInfo(Method method, Class<?>[] ifcs) {
273+
RequestMapping requestMapping = AnnotationUtils.searchOnInterfaces(method, RequestMapping.class, ifcs);
274+
RequestCondition<?> condition = getCustomMethodCondition(method);
275+
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
276+
}
262277

263278
/**
264279
* Provide a custom type-level request condition.

0 commit comments

Comments
 (0)