spring-cloud-openfeign icon indicating copy to clipboard operation
spring-cloud-openfeign copied to clipboard

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

Open letian-tang opened this issue 2 years ago • 12 comments

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");
		}
	}

letian-tang avatar Apr 02 '22 13:04 letian-tang

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

like this:

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

shinestmt avatar Apr 09 '22 12:04 shinestmt

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.

mschreiber-emineo avatar Apr 21 '22 11:04 mschreiber-emineo

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

skubicz avatar Apr 29 '22 13:04 skubicz

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

p-jakubczyk avatar Apr 29 '22 14:04 p-jakubczyk

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

DestroTM avatar Apr 29 '22 17:04 DestroTM

I have the same problem... 🔥🤬

klolo avatar Apr 30 '22 05:04 klolo

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

ziarniakm avatar May 02 '22 06:05 ziarniakm

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

mschreiber-emineo avatar May 02 '22 06:05 mschreiber-emineo

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.

oymy avatar May 12 '22 10:05 oymy

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

ITG001 avatar Jun 22 '22 08:06 ITG001

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.


ardc-shorn avatar Aug 08 '22 08:08 ardc-shorn

mark,i have the same problem

malaxiaolongxia avatar Aug 15 '22 09:08 malaxiaolongxia

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.

OlgaMaciaszek avatar Sep 05 '22 10:09 OlgaMaciaszek