feignClient injection failed

When the newly created service provides feign calls, the caller cannot inject the provider's feign. Approximate error message:

no qualifying bean of type available

Caller's startup class annotation

@ComponentScan({"com.plumelog","com.admin.**"})
@SpringBootApplication
public class AdminApplication {
   
   

Provider startup class annotations

@ComponentScan({"com.plumelog","com.push.service.**"})
@EnableFeignClients(basePackages = "com.**")
@SpringBootApplication
public class PushServiceApplication {
   
   

found that the caller did not

@EnableFeignClients(basePackages = "com.**") annotation, so after the caller adds this annotation, other errors are reported:
***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'authentication-feign.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Roughly, this bean already exists, whether to configure spring.main.allow-bean-definition-overriding=true

Go to cover it, and then report other feign injection failures after adding this configuration.

Analysis of the cause of the error:

Locate authentication-feign and check that the service provides automatic assembly under feign, which is automatically injected when the project starts. If the caller starts the class and adds the @EnableFeifnClients annotation, the bean will be injected twice, so the caller does not need the @EnableFeifnClients annotation. But if you don't configure automatic assembly, you need to rely on the @EnableFeifnClients annotation, which is contradictory.

@Configuration
@EnableFeignClients(basePackages = "com.authorization.client.feign")
@ComponentScan(basePackages = "com.authorization.client.feign")
public class ClientAutoConfiguration {
   
   

Solution: Add the automatic assembly configuration under the feign package of the new service.

Guess you like

Origin blog.csdn.net/Json_Marz/article/details/127007277