新建的服务提供feign调用时,调用方无法注入提供方的feign。大致的报错信息:

no qualifying bean of type available

调用方的启动类注解

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

提供方启动类注解

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

发现调用方没有

@EnableFeignClients(basePackages = "com.**") 注解,于是调用方加上这个注解后,报其他错误:
***************************
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

大致意思是,已经存在这个bean了,是否配置 spring.main.allow-bean-definition-overriding=true

去覆盖它,然后加上此配置后报其他的feign注入失败。

报错原因分析:

定位到authentication-feign,查看该服务在feign下提供了自动装配,项目启动时自动注入,如果调用方启动类加上@EnableFeifnClients注解就会注入两次bean,所以在调用方不需要@EnableFeifnClients注解。但是不配置自动装配就要依赖@EnableFeifnClients注解,这就互相矛盾了。

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

解决方案:在新服务的feign包下也加上自动装配配置。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐