新建的服务提供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包下也加上自动装配配置。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/70911.html