Spring cloud uses feignclient to start and report an error

Let’s first look at the error message


Field businessFeignClient in com.ysc.service.BusinessConfigService required a bean of type 'com.ysc.feignclient.BusinessFeignClient' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Consider defining a bean of type 'com.ysc.feignclient.BusinessFeignClient' in your configuration.

Let’s take another look at feign’s configuration information

        scanBasePackages = "com.ysc",
        exclude = {
public class Application {
	public static void main(String[] args) {
        SpringApplication.run(Application.class, args);


On the surface, there is no problem with the configuration. Let’s analyze the specific causes of the problem

The annotation @ enablefeignclients conflicts with @ componentscan. Both annotations will search for beans injected into the specified [email protected] Enablefeignclients introduces the feignclientsregister class to load spring bean resources

The registerfeignclients method in feignclientsregister obtains the basepackage attribute value in the @ enablefeignclients annotation and injects it. If both annotations are used, @ enablefeignclients will overwrite the directory specified in @ componentscan to restore to the default directory

How to solve this problem:

1. Feignclient can be placed in the same level directory as the application startup class

2. You can specify the bean directory through the clients property in @ enablefeignclients

@EnableFeignClients(clients = {

Similar Posts: