Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot FeignClient Method has too many paramters

im using spring-cloud's feignClient and things go wrong when there is more than one Beans paramters in my interface,error shows like:

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.wxl.pros.test.web.common.CommonResObject com.wxl.pros.test.web.feign.OrderFeignClient.createOrder(com.wxl.pros.test.services.form.order.CreateOrderForm,com.wxl.pros.test.services.vo.User)
    at feign.Util.checkState(Util.java:128)
    at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:114)
    at org.springframework.cloud.netflix.feign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:133)
    at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64)
    at feign.hystrix.HystrixDelegatingContract.parseAndValidatateMetadata(HystrixDelegatingContract.java:34)
    at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146)
    at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53)
    at feign.Feign$Builder.target(Feign.java:209)
    at org.springframework.cloud.netflix.feign.HystrixTargeter.target(HystrixTargeter.java:48)
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:184)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
    ... 27 common frames omitted

Here is one of my interface methods:

@RequestMapping(value="/order/createOrder",method=RequestMethod.POST)
    public CommonResObject createOrder(@RequestBody OrderForm orderForm,@RequestBody User user);
like image 982
W.Lin Avatar asked Apr 25 '17 07:04

W.Lin


People also ask

Can we use feign client without Eureka?

Yes you can use Feign without Ribbon, All you need to do is specify the base url in your Feign Java interface class.

How do you connect two Microservices using Feign client?

Let's implement the Feign in our project and invoke other microservices using Feign. Step 1: Select currency-conversion-service project. Step 2: Open the pom. xml and add the Feign dependency.

Is feign client blocking?

Reactive Feign is great choice for the implementation of non-blocking API clients. It is a reactive version of OpenFeign which supports the creation of API clients without the need to writing implementation code. By just defining interface and configuration, development of API clients can be done effortlessly.

How do you pass a path variable in feign client?

To map the path variable to a method argument in a feign client, we use the @PathVariable annotation from Spring. String getThirdService(@PathVariable(name = "id") int id); Using the annotation as such, OpenFeign will substitute the {id} part of the path with the value of the integer id.


1 Answers

If you have multiple arguments with one request body and more params. Specify the argument types using exact annotations:

ResponseMessage<String> getCustomInformation((@RequestBody CustomRequest request, @RequestParam("language") String language,
            @RequestParam("channel") String channel, @RequestParam("requestId") String requestId
like image 101
nanospeck Avatar answered Sep 21 '22 03:09

nanospeck