zoukankan      html  css  js  c++  java
  • 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博客
       格言:能力是金钱的另一种保存方式
       版权声明:本文为博主原创文章,如需转载请注明出处

  • 相关阅读:
    ReactNative入门 —— 动画篇(下)
    浅谈浏览器http的缓存机制
    ReactNative入门 —— 动画篇(上)
    小小改动帮你减少bundle.js文件体积(翻译)
    ReactNative入门(安卓)——API(上)
    《高性能javascript》一书要点和延伸(下)
    巧用 mask-image 实现简单进度加载界面
    降低首屏时间,“直出”是个什么概念?
    AlloyTeam2015前端大会都说了啥
    作为前端er,写在年末的一些话
  • 原文地址:https://www.cnblogs.com/cosmosray/p/13268770.html
Copyright © 2011-2022 走看看