文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

SpringbootFeignClient调用MethodhastoomanyBodyparameters解决

2024-04-02 19:55

关注

背景:在做多服务之间需要使用FeignClient进行服务调用的时候,出现PathVariable annotation was empty on param 0.,根据提示需要指定value的值,以下为具体解决过程



@Component
@FeignClient(value = "nuclear-core", fallback = CoreHystrixClientFallback.class)
public interface CoreServiceFeignClient {
 
    @GetMapping("{deviceId}/statistics/warning")
    ReturnResponse statisticsWarmingPoints(@PathVariable Long deviceId, Long startTime, Long endTime);
}

启动后报错代码为:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportApplication': Unsatisfied dependency expressed through field 'reportUtils'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportUtils': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportDataOperationServiceImpl': Unsatisfied dependency expressed through field 'coreFeignClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.aimsphm.nuclear.report.feign.CoreServiceFeignClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException:
PathVariable annotation was empty on param 0.
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1404) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]

第二行实际为重点语句:描述为PathVariable注解作为第一个参数不能为空

改动为:


@GetMapping("{deviceId}/statistics/warning")
ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, Long startTime, Long endTime)

重新启动后:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportApplication': Unsatisfied dependency expressed through field 'reportUtils'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportUtils': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportDataOperationServiceImpl': Unsatisfied dependency expressed through field 'coreFeignClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.aimsphm.nuclear.report.feign.CoreServiceFeignClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException:
 Method has too many Body parameters: public abstract com.aimsphm.nuclear.common.response.ReturnResponse com.aimsphm.nuclear.report.feign.CoreServiceFeignClient.statisticsWarmingPoints(java.lang.Long,java.lang.Long,java.lang.Long)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1404) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847) ~[spring-beans-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.13.RELEASE.jar:5.1.13.RELEASE]
 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]
 at com.aimsphm.nuclear.report.ReportApplication.main(ReportApplication.java:28) [classes/:na]

依然是第二行描述为:在body中的参数有太多了,所以此时,首先确定参数是否是在body中,如果是的话,应该合成一个参数进行传递,如果不是的话,看是否应该是采用@RequestParam注解,本例中不是body中的参数,故采用@RequestParam注解

再次改动后:


 @GetMapping("{deviceId}/statistics/warning")
 ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, @RequestParam Long startTime, @RequestParam Long endTime);

再次启动后仍旧报错:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportApplication': Unsatisfied dependency expressed through field 'reportUtils'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportUtils': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reportDataOperationServiceImpl': Unsatisfied dependency expressed through field 'coreFeignClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.aimsphm.nuclear.report.feign.CoreServiceFeignClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException:
RequestParam.value() was empty on parameter 1

可以看到,现在报错是说参数2的value注解是空,以此再次修改


@GetMapping("{deviceId}/statistics/warning")
ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, @RequestParam(value = "startTime") Long startTime, @RequestParam(value = "endTime") Long endTime);

然后重新启动,成功!!

仅此,记录,下次少走弯路...

到此这篇关于Springboot FeignClient微服务间调用Method has too many Body parameters 解决的文章就介绍到这了,更多相关Springboot FeignClient微服务间调用 内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯