Description
s-mop opened SPR-17223 and commented
Here is the demo codes:
@RequestMapping(value = "order/customer")
@RestController
public interface CunstomerOrderClient {
@PostMapping("rating")
String rating();
}
public class AbstractOrderService {
public String rating() {
return "rated";
}
}
@Service
public class CustomerOrderService extends AbstractOrderService implements CunstomerOrderClient {
}
"order/customer/rating" dosnt registered as I expected
I tried to find reason and get these codes in spring-webmvc:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getMappingForMethod(Method, Class<?>)
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = createRequestMappingInfo(method);
if (info != null) {
RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
if (typeInfo != null) { info = typeInfo.combine(info); }
}
return info;
}
and
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.createRequestMappingInfo(AnnotatedElement)
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class ? getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
}
These codes seems like try to find @ReqeuestMapping
in super class or interface of witch i defined my 'ranking' method
Of course they can't find @ReqeuestMapping
because the 'ranking' method is defined in AbstractOrderService, and AbstractOrderService is not implements CunstomerOrderClient.
Affects: 5.0.5
Issue Links:
- Enable REST controller method parameter annotations on an interface [SPR-11055] #15682 Enable REST controller method parameter annotations on an interface
- AOP support for SPR-17223 & PR#1950 [SPR-17496] #22028 AOP support for SPR-17223 & SPR-17223 - Support for methods that are declared in interfaces and implemented in super class #1950
Referenced from: pull request #1950