org.springframework.beans.factory.UnsatisfiedDependencyException

springboot整合feign时报错

报错信息如下(截取前段部分信息)

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportController': Unsatisfied dependency expressed through field 'reportService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportServiceImpl': Unsatisfied dependency expressed through field 'uiasUserController'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.net.topnet.base.UiasUserController': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract java.util.Map cn.net.topnet.base.UiasUserController.getMsgByUserId(java.lang.String,java.lang.String)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
	at cn.net.topnet.ReportApplication.main(ReportApplication.java:24)

主要部分

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportController': Unsatisfied dependency expressed through field 'reportService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportServiceImpl': Unsatisfied dependency expressed through field 'uiasUserController'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.net.topnet.base.UiasUserController': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract java.util.Map cn.net.topnet.base.UiasUserController.getMsgByUserId(java.lang.String,java.lang.String)

经查询,定义的feigin接口类如下

@FeignClient(value = "uias")
public interface UiasUserController {

    @GetMapping(value = "/uias/user/getMsgByUserId")
    Map getMsgByUserId(@Param("userId")String userId, @Param("postId")String postId);
}

在参数定义方面使用的@Param注解,修改为@RequestParam修改后

@FeignClient(value = "uias")
public interface UiasUserController {

    @GetMapping(value = "/uias/user/getMsgByUserId")
    Map getMsgByUserId(@RequestParam("userId")String userId, @RequestParam("postId")String postId);
}

查询相关博客,获得解释为

@RequestParam 用于controller层
(1)解决前台参数名称与后台接收参数变量名称不一致的问题,等价于request.getParam
(2)可设置value:指定参数名 default:指定变量初始值 require(true默认/false):指定参数是否为必传

@Param 用于dao层
个人理解为修饰参数,使得mapper.xml中的参数与后台的参数对应上,也增强了可读性
如果两者参数名一致得话,spring会自动进行封装,不一致的时候就需要手动去使其对应上。

看了下注解源码,两种注解的接口类有所区别,限于水平有限,暂不做深入研究,如有道友指教一二,在下不胜感激涕零

 


CosmosRay

    cosmosray@aliyun.com
   CSDN博客
   格言:能力是金钱的另一种保存方式
   版权声明:本文为博主原创文章,如需转载请注明出处

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值