Skip to content

getMappingForMethod failed when implement a interface method(with @RequestMapping) in super class [SPR-17223] #21756

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: pull request #1950

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions