Springboot FeignClient調(diào)用Method has too many Body parameters解決
背景:在做多服務(wù)之間需要使用FeignClient進(jìn)行服務(wù)調(diào)用的時(shí)候,出現(xiàn)PathVariable annotation was empty on param 0.,根據(jù)提示需要指定value的值,以下為具體解決過程
/**
* @Package: com.aimsphm.nuclear.data.feign
* @Description: <服務(wù)調(diào)用>
* @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);
}
啟動(dòng)后報(bào)錯(cuò)代碼為:
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]
第二行實(shí)際為重點(diǎn)語句:描述為PathVariable注解作為第一個(gè)參數(shù)不能為空
改動(dòng)為:
@GetMapping("{deviceId}/statistics/warning")
ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, Long startTime, Long endTime)
重新啟動(dòng)后:
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中的參數(shù)有太多了,所以此時(shí),首先確定參數(shù)是否是在body中,如果是的話,應(yīng)該合成一個(gè)參數(shù)進(jìn)行傳遞,如果不是的話,看是否應(yīng)該是采用@RequestParam注解,本例中不是body中的參數(shù),故采用@RequestParam注解
再次改動(dòng)后:
@GetMapping("{deviceId}/statistics/warning")
ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, @RequestParam Long startTime, @RequestParam Long endTime);
再次啟動(dòng)后仍舊報(bào)錯(cuò):
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
可以看到,現(xiàn)在報(bào)錯(cuò)是說參數(shù)2的value注解是空,以此再次修改
@GetMapping("{deviceId}/statistics/warning")
ReturnResponse statisticsWarmingPoints(@PathVariable(value = "deviceId") Long deviceId, @RequestParam(value = "startTime") Long startTime, @RequestParam(value = "endTime") Long endTime);
然后重新啟動(dòng),成功??!
僅此,記錄,下次少走彎路...
到此這篇關(guān)于Springboot FeignClient微服務(wù)間調(diào)用Method has too many Body parameters 解決的文章就介紹到這了,更多相關(guān)Springboot FeignClient微服務(wù)間調(diào)用 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用@Order控制配置類/AOP/方法/字段的加載順序詳解
這篇文章主要介紹了使用@Order控制配置類/AOP/方法/字段的加載順序詳解,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
MyBatis的mapper.xml文件中入?yún)⒑头祷刂档膶?shí)現(xiàn)
這篇文章主要介紹了MyBatis的mapper.xml文件中入?yún)⒑头祷刂档膶?shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
Java中的Map接口實(shí)現(xiàn)類HashMap和LinkedHashMap詳解
這篇文章主要介紹了Java中的Map接口實(shí)現(xiàn)類HashMap和LinkedHashMap詳解,我們常會看到這樣的一種集合,IP地址與主機(jī)名,等,這種一一對應(yīng)的關(guān)系,就叫做映射,Java提供了專門的集合類用來存放這種對象關(guān)系的對象,需要的朋友可以參考下2024-01-01
Java實(shí)現(xiàn)lucene搜索功能的方法(推薦)
下面小編就為大家?guī)硪黄狫ava實(shí)現(xiàn)lucene搜索功能的方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12
一文搞懂SpringBoot如何利用@Async實(shí)現(xiàn)異步調(diào)用
異步調(diào)用幾乎是處理高并發(fā),解決性能問題常用的手段,如何開啟異步調(diào)用?SpringBoot中提供了非常簡單的方式,就是一個(gè)注解@Async。今天我們重新認(rèn)識一下@Async,以及注意事項(xiàng)2022-09-09
spring boot 打包jar jar沒有主目錄清單問題的完美解決方法
這篇文章主要介紹了spring boot 打包jar jar沒有主目錄清單問題的解決方法,本文是小編第一次寫,希望對大家有所幫助2018-07-07

