创建Feign客户端报错:UnsatisfiedDependencyException: Error creating bean with name ‘xxxUtil‘


一、场景

1、创建Feign客户端报错


二、报错信息

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxUtil': Unsatisfied dependency expressed through field 'xxxApiFeignClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xxx.feign.xxxApiFeignClient': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.alibaba.fastjson.JSONObject com.xxx.feign.xxxApiFeignClient.getHotQuestions(java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,java.lang.String)
Warnings:
- 
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657)
	... 20 common frames omitted

三、Feign客户端代码

@FeignClient(name = "defaultxxxApi-cloud", contextId = "xxxApiFeignClient", path = "defaultxxxApiPath")
@RefreshScope
public interface xxxApiFeignClient {

    @PostMapping(value = "/xxx_api/getHotQuestions")
    JSONObject getHotQuestions(String cId, String appId,
                               String apiId, String openId,
                               int top, String type);
}

四、原因

当Feign客户端接口参数数量超过1个时,需要为接口参数指定参数名称


五、解决

使用@RequestParam注解为接口参数指定参数名称

@FeignClient(name = "defaultxxxApi-cloud", contextId = "xxxApiFeignClient", path = "defaultxxxApiPath")
@RefreshScope
public interface xxxApiFeignClient {

    @PostMapping(value = "/robot_api/visitor/getHotQuestions")
    JSONObject getHotQuestions(@RequestParam(value = "cId") String cId, @RequestParam(value = "appId") String appId,
                               @RequestParam(value = "apiId") String apiId, @RequestParam(value = "openId") String openId,
                               @RequestParam(value = "top") int top, @RequestParam(value = "type") String type);
}
  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值