FeignClient annotation and parameter problems -- spring cloud microservices

1, Foreword Feign client is a common annotati...
1, Foreword

Feign client is a common annotation and very important function in the development of spring cloud technology with distributed architecture spring boot.

The simple understanding is that the core of internal communication between the distributed architecture services and each sub module system.

Generally, it is used when one system calls the interface of another system, as follows:

annotation

@FeignClient("XXX") public interface XX{ .... }

This annotation is generally created in the interface interface, and then it is very easy to use in the business class @ Autowired.

2, Problem background

After the interface is created, of course, the interface method calling the service must be defined. The method corresponds to the controller interface of the FeignClient, and the interface method must be rewritten (the return object and the parameter value are exactly the same).

When the startup project reported the following error, it was considered that the call was empty null when it was invoked in the business class.

FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0

When the parameter is replaced by data, the system will restart and still report the above error.

Post a screenshot of error reporting

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'withdrawCountRecordController': Unsatisfied dependency expressed through field 'withdrawCountService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'withdrawCountServiceImpl': Unsatisfied dependency expressed through field 'cumClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.epaylinks.efps.pas.clr.client.CumClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

3, Solutions

In the @ FeignClien("XX") interface class, when checking the parameter definition of each method:

Is there any of the following

@RequestMapping(value="/XXX/query", method = RequestMethod.GET) public PageResult<XXutionResp> query(@RequestParam(required = false) String XXCode, @RequestParam(value = "XXnName",required = false) String institutionName, @RequestParam(value = "startTime",required = false) String startTime,

Here's the problem:

@RequestParam(required = false) String XXCode

This parameter is missing value = "XXCode", this is spring Four After the version, the @ RequestParam annotation has a good encapsulation feature for parameter values and strict verification.

Change to: @ RequestParam(value = "XXCode", required = false) String XXCode

After that, the problem is solved perfectly; the restart project is normal.

In addition, insert a sentence: when calling the same @ FeignClien("XX") project in multiple places of the project, creating interfaces in multiple packages has no effect.

Pay attention to official account: the big vision of procedure

Feel helpful to you, pay attention to blog and official account. From time to time, we will share the latest cutting-edge technology framework and common technologies of bat plant, and from time to time, we will share live lectures of Daniel in the industry and obtain video courseware materials.

17 May 2020, 04:59 | Views: 6832

Add new comment

For adding a comment, please log in
or create account

0 comments