spring-cloud / spring-cloud-openfeign

Support for using OpenFeign in Spring Cloud apps
Apache License 2.0
1.19k stars 774 forks source link

【help】why throw new IllegalArgumentException("@RequestMapping annotation not allowed on @FeignClient interfaces"); #698

Closed letian-tang closed 2 years ago

letian-tang commented 2 years ago

why version3.0.5 begin throw new IllegalArgumentException("@RequestMapping annotation not allowed on @FeignClient interfaces");

protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
        RequestMapping classAnnotation = findMergedAnnotation(clz, RequestMapping.class);
        if (classAnnotation != null) {
            LOG.error("Cannot process class: " + clz.getName()
                    + ". @RequestMapping annotation is not allowed on @FeignClient interfaces.");
            throw new IllegalArgumentException("@RequestMapping annotation not allowed on @FeignClient interfaces");
        }
    }
shinestmt commented 2 years ago

https://github.com/shinestmt/webmvc-rpc-starter.git

like this:

webmvc-rpc-spring-boot-starter-client # RequestMappingFeignClientSpringMvcContract

mschreiber-emineo commented 2 years ago

I just updated an application and did run into the same issue. I have an application that exposes an API and I'm using tests that create a feign client with FeignBuilder and uses the same class that is exposed for testing. This does not work anymore, that's quite sad.

skubicz commented 2 years ago

Also, I don't understand this change. I don't want Feign annotations in my API so now this client is useless to me.

p-jakubczyk commented 2 years ago

Agree with the above, it makes the client useless to me as well.

DestroTM commented 2 years ago

Also, I have the same issue. Is this change really necessary?

klolo commented 2 years ago

I have the same problem... 🔥🤬

ziarniakm commented 2 years ago

Also , i have the same problem. What was the reason of this change ?

mschreiber-emineo commented 2 years ago

Also , i have the same problem. What was the reason of this change ? See here: https://github.com/spring-cloud/spring-cloud-netflix/issues/466

oymy commented 2 years ago

I have the same problem.

it make it difficult to let the controller implement the feignclient interface. eg. ` @FeignClient("path=test") public interface TestClient { }

@RestController public class TestController implements TestClient } `

now the TestController need to adds a @RequestMapping("test") to make it work.

ITG001 commented 2 years ago

Also , i have the same problem. What was the reason of this change ?

ardc-shorn commented 2 years ago

And now with version 6.2.0 of openapi-generator - my project has started failing because they added @RequestMapping in the api.mustache file for the JavaSpring module.

I currently work around this by using a custom api.mustache template file with the RequestMapping removed.

It would be beneficial for both openapi-generator and spring-cloud-openfeign project to get on the same page so they can work together.


The below was true, but I was generating the code via openapi incorrectly. If setup properly for my use-case, openapi does not generate @RequestMapping on the interface and I can use a feign client for testing just fine. Just wanted to point out that openfeign works fine with output from openapi, if its configured appropriately.


Same issue as other folks. I'm generating my API interface with openapi, then it's implemented in Spring (pure Spring, not spring-boot). In my integration tests, I build a Feign client to call the server - but it fails with this message.


malaxiaolongxia commented 2 years ago

mark,i have the same problem

OlgaMaciaszek commented 2 years ago

Hello, @letian-tang, this was done on purpose (see https://tanzu.vmware.com/security/cve-2021-22044 and https://github.com/spring-cloud/spring-cloud-openfeign/issues/547). It was always discouraged as a bad practice in the docs. Since it also caused a security issue, the team has decided to remove it. Closing as duplicate of gh-678.