Describe the bug

Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'xxx.TestFeignClient' method 
xxx.TestFeignClient#invoke(String)
to {GET /test/invoke}: There is already 'testController' bean method
xxx.TestController#invoke(String) mapped.

Sample

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestFeignClient testFeignClient;

    @GetMapping("/invoke")
    public String invoke() {
        return testFeignClient.invoke();
    }
}
@FeignClient("some-service")
@RequestMapping("/test")
public interface TestFeignClient {
    @GetMapping("/invoke")
    public String invoke();
}

I want to explain why does TestFeignClient write like this. In fact, the interface of service provider is similar to TestController. When I want to access it with OpenFeign, a quick way is to copy it to my project and change @RestController to @FeignClient, and then delete the method body. right?

Back to the topic, why does the handler defined by OpenFeign conflict with the handler of spring mvc?

Comment From: markixy

The essence of the problem seems to be that as long as @RequestMapping appears on the class, it will be registered into springmvc. The relevant code looks like: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#isHandler.

protected boolean isHandler(Class<?> beanType) {
    return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
        AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class));
}

I am confused, why the judgment condition is not just AnnotatedElementUtils.hasAnnotation(beanType, Controller.class)?

Comment From: OlgaMaciaszek

Yes, @RequestMapping should not be there at class level in a Feign Client.