Problem of repeatedly defining feign client based on multiple consumers of spring cloud

  • 2021-11-29 23:49:39
  • OfStack

Multiple consumers of the directory springcloud repeatedly define feign client and report errors in spring cloud+feignClient

springcloud Multiple consumers repeatedly define feign client

spring cloud consumer calls the service provider in two ways: rest + ribbon and Feign. Feign is a declarative pseudo Http client, which is simpler and easier to use, so Feign is selected as the service communication mode in our project

There are six modules in the project, A, B, C, D, E and F. It is necessary to call each other before the modules

Here comes the problem. To invoke the server by FeignClient, it is necessary to establish the FeignClient interface for invoking the server at the consumer

Suppose both A and B need to call C. To call C from A, one FeignClient interface of C should be established in A module When B calls C, one FeignClient interface of C needs to be established in B module If C module is needed for D, E and F, three FeignClient need to be established. And the codes in these FeignClient are all the same.

In this case, can FeignClient interface be defined as a general interface?

The author tries to set up a module G for FeignClient, and manages the FeignClient call interface of each module in the module G. When A, B, C, D, E and F are intermodulated, only G module needs to be introduced into pom.

The idea was beautiful, the reality was cruel, and the experiment failed.

After the module G is introduced, SpringBoot is started to control error reporting. bean could not be found.

The consumer startup class Application has a scan package annotation @ ComponentScan (basePackages= {"com. chelizi. feign. intf"})

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'com.chelizi.feign.intf.system.SysSerialNumberController' that could not be found.


Action:

Consider defining a bean of type 'com.chelizi.feign.intf.system.SysSerialNumberController' in your configuration.

With the @ ComponentScan annotation above, the normal @ Component under com. chelizi. feign. intf or JavaBean of @ Service can be scanned, but the @ FeignClient class cannot be scanned

Error report at spring cloud+feignClient

Error Consider defining a bean of type 'xxxx' in your configuration in spring cloud + feignClient

Most of the main reasons are that they are not enabled


Related articles: