Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of calling error in Springboot FeignClient

Shulou Source: shulou.com Published: 2022-06-02 04:43:42 10月01日 Update

This article mainly explains "how to solve Springboot FeignClient call error". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to solve Springboot FeignClient call error report.

Background: when you need to use FeignClient for service invocation between multiple services, PathVariable annotation was empty on param 0 appears. Specify the value of value according to the prompt. The following is the specific solution process.

/ * @ Package: com.aimsphm.nuclear.data.feign * @ Description: * @ Author: MILLA * @ CreateDate: 2020-3-31 15:22 * @ UpdateUser: MILLA * @ UpdateDate: 2020-3-31 15:22 * @ UpdateRemark: * @ Version: 1.0 * / @ Component@FeignClient (value = "nuclear-core", fallback = CoreHystrixClientFallback.class) public interface CoreServiceFeignClient {@ GetMapping ("{deviceId} / statistics/warning") ReturnResponse statisticsWarmingPoints (@ PathVariable Long deviceId, Long startTime Long endTime) }

The error code after startup is:

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]

The second line is actually the key statement: described as PathVariable comments cannot be empty as the first parameter

Change it to:

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

After reboot:

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]

The second line is still described as: there are too many parameters in body, so at this point, first determine whether the parameter is in body. If so, you should synthesize a parameter to pass. If not, see whether the @ RequestParam annotation should be used. In this case, it is not the parameter in body, so the @ RequestParam annotation is used.

After changing it again:

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

Still report an error after starting again:

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

As you can see, the error report now means that the value annotation of parameter 2 is empty, so you can modify it again.

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

Then restart, successful!

Thank you for your reading, the above is the content of "Springboot FeignClient call error report how to solve", after the study of this article, I believe you have a deeper understanding of how to solve this problem, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Parameters annotations again learning content services success between code reality that is ideas situations articles time is in yes more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn Xiaomi macOS NVidia